我有一个重定向问题。我有我的htaccess的设置,以从URL执行下列操作... 1.删除PHP扩展 2.添加自定义错误页 3.强制一些301重定向重定向问题和htaccess
但与重定向一个巨大的问题... 如果用户去... www.mysite.com/articles/jewelry/types.php ...然后,基于第二次301重定向,他们应该被发送到... www.mysite.com/article/medieval-jewelry-types-and-functions/ ...但是,它们被重定向到... www.mysite.com/article/medieval-jewelry/types
如果他们去... www.mysite.com/articles/picks/A_1.php ...他们应该被重定向到... www.mysite.com/article/picks-tools/ ...但是他们得到发送... www.mysite.com/article/how-to-pick/
它看起来像重定向正在改变网址的一部分...可能是因为.php扩展名(但只是猜测 - 因为我对编辑htaccess文件知之甚少)。有任何想法吗?
下面是我的大多数htaccess文件中,对什么可能导致该问题的一些意见。任何想法如何解决它?
# enable the rewrite engine
RewriteEngine On
# Set your root directory
RewriteBase/
# remove the .php extension
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# remove index and reference the directory
RewriteRule (.*)/index$ $1/ [R=301]
# remove trailing slash if not a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# forward request to html file, **but don't redirect (bot friendly)**
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
ErrorDocument 400 /400.php
ErrorDocument 401 /401.php
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
ErrorDocument 405 /405.php
ErrorDocument 408 /408.php
ErrorDocument 414 /414.php
ErrorDocument 500 /500.php
ErrorDocument 502 /502.php
ErrorDocument 504 /504.php
# example of redirects
Redirect 301 /articles/index.php /articles/
# it looks like the redirect below is conflicting with...
Redirect 301 /articles/jewelry/ /article/medieval-jewelry/
# ... this redirect.
Redirect 301 /articles/jewelry/types.php /article/medieval-jewelry-types-and-functions/
# And this redirect...
Redirect 301 /articles/picks/ /article/how-to-pick/
Redirect 301 /articles/picks/index.php /article/how-to-pick/
# ... is conflicting with this one...
Redirect 301 /articles/picks/A_1.php /article/picks-tools/
我会检查出来......我注意到,我正在写入重定向为... /articles/picks/A_1.php ...并且您使用了... ^文章/选择/ A_1 \ .php $ ...你能解释一下你做了什么以及你的语法是如何工作的?我试图更好地理解这一点... – Jabbamonkey
对不起,因为我在手机上打字时输入错字。引导斜杠在htaccess上不匹配,点是需要转义的特殊字符。请测试一下,让我知道这是否可行。 – anubhava
看起来不错。谢谢您的帮助。我需要了解更多关于htaccess文件... – Jabbamonkey