[英]No redirection (rewrite) from one folder to another folder
Following is my full htaccess file. 以下是我完整的htaccess文件。
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#redirect index to homepage
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#prevent hotlinking
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?www.example.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
#redirect galleries to portfolio
RewriteRule ^galleries/(.*)$ /portfolio/$1 [R=301,NC,L]
#prevent access to wp-config
<files wp-config.php>
order allow,deny
deny from all
</files>
</IfModule>
The following one is obviously the one in question: 下面的一个显然是有问题的:
#redirect galleries to portfolio
RewriteRule ^galleries/(.*)$ /portfolio/$1 [R=301,NC,L]
If I go to http://subdomain.example.com/galleries/headshots/
the server should redirect to http://subdomain.example.com/portfolio/headshots/
如果我转到
http://subdomain.example.com/galleries/headshots/
则服务器应重定向到http://subdomain.example.com/portfolio/headshots/
Nothing at all happens, I remain on http://subdomain.example.com/galleries/headshots/
. 什么都没有发生,我仍然停留在
http://subdomain.example.com/galleries/headshots/
。
I added slashes at the end of both, the source and target - nothing changed: 我在源和目标的末尾都添加了斜杠-没有改变:
#redirect galleries to portfolio
RewriteRule ^galleries/(.*)$/ /portfolio/$1/ [R=301,NC,L]
Also tried putting the directive on top, just below RewriteBase /
- still no luck. 还尝试将指令放在
RewriteBase /
下方的RewriteBase /
-还是没有运气。
Note that this happens on a subdomain (see example url), although I don't think that has an impact on this behaviour. 请注意,这发生在子域上(请参见示例url),尽管我认为这不会影响此行为。
This is happening on a Wordpress installation, but I have doubts it influences that. 这是在Wordpress安装上发生的,但是我怀疑它是否会影响安装。 All the other directives seem to work fine (react on change).
所有其他指令似乎都可以正常工作(对更改做出反应)。
Edit (from the comment reply to @Panama Jack): Both directories actually exist and are separate pages, but one is only setup as a script, if you like (other pages have to access its gallery). 编辑 (来自对@Panama Jack的评论回复):两个目录实际上都存在并且是单独的页面,但是如果您愿意的话,只能将其设置为脚本(其他页面必须访问其库)。
In your rewrite rule the URL should start with a /. 在您的重写规则中,URL应该以/开头。
Besides, the part (.*)$/
is very strange: you are first looking for anything until the end and then adding a slash. 此外,
(.*)$/
部分非常奇怪:您首先要查找任何内容,直到结尾,然后添加斜杠。 Did you want to limit the rewrite rules to directories? 您是否要将重写规则限制为目录? Then why not including the trailing slash in the pattern:
(.*)/$
? 然后,为什么不在模式中包含尾部斜杠:
(.*)/$
?
The below rule would redirect everything below /galleries/
以下规则将重定向
/galleries/
所有内容
RewriteRule ^/galleries/(.*)$ /portfolio/$1 [R=301,NC,L]
Slash is in the wrong place. 斜杠在错误的位置。 Change this
改变这个
RewriteRule ^galleries/(.*)$/ /portfolio/$1/ [R=301,NC,L]
to this 对此
RewriteRule ^galleries/(.*)/$ /portfolio/$1/ [R=301,NC,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.