[英]Simple Apache Rewrite Rule Giving Unwanted 404
I have the following rewrite rule: RewriteRule ^/uk/(.*)$ http://www.hostname.uk/$1 [R,L]
我有以下重写规则:
RewriteRule ^/uk/(.*)$ http://www.hostname.uk/$1 [R,L]
which rewrites the url from: 它重写了以下网址:
http://www.hostname.uk/uk/home
to http://www.hostname.uk/uk/home
来 http://www.hostname.uk/home
However instead of seeing the content at http://www.hostname.uk/uk/home
with the shorter address you get a blank 404 page instead. 但是,不要使用较短的地址查看
http://www.hostname.uk/uk/home
上的内容,而是获得一个空白的404页面。 Why is this? 为什么是这样? How do I fix this?
我该如何解决?
The rule you have is redirecting from /uk/home
to /home
, but you don't have anything in place to rewrite in the other direction. 你有的规则是从
/uk/home
重定向到/home
,但你没有任何东西可以在另一个方向上重写。 This is what you need. 这就是你需要的。 You should also use a 301 redirect (permanent) which I did here.
您还应该使用我在此处执行的301重定向(永久)。 You were using a 302 (temporary - the default).
您使用的是302(临时 - 默认值)。 You also don't need to specify the
http://www.hostname.uk
when it's not changing. 当它没有改变时,你也不需要指定
http://www.hostname.uk
。
RewriteRule ^/uk/(.*)$ /$1 [R=301,L]
RewriteRule ^/(.*)$ /uk/$1 [L]
I am assuming you are doing this in your main Apache configuration. 我假设您在主Apache配置中执行此操作。 If it's in your
.htaccess
then it will need changing. 如果它在你的
.htaccess
,则需要更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.