Htaccess 规则给出 301 错误
Posted
技术标签:
【中文标题】Htaccess 规则给出 301 错误【英文标题】:Htaccess rule giving 301 error 【发布时间】:2014-08-08 10:12:19 【问题描述】:我正在尝试更改 URL,在我的 htaccess 中我添加了这一行:
RewriteRule ^/about/$ /site/about_us/
添加后,如果我点击我的 URL http://mydomain.com/about/
,它会给我 301 永久移动并重定向到 http://mydomain.com/site/about_us/
我的 htaccess 文件:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^about/?$ /site/about_us/ [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
标题:
Response Heades:
HTTP/1.1 301 Moved Permanently
Date: Wed, 18 Jun 2014 09:42:45 GMT
Server: Apache/2.4.4 (Win64) PHP/5.4.12
X-Powered-By: PHP/5.4.12
X-Pingback: http://soller.local/xmlrpc.php
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
Location: http://soller.local/site/about_us/
Content-Length: 0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
Request Heades:
GET /about/ HTTP/1.1
Host: soller.local
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: wp-settings-time-1=1393072512; wp-settings-1=libraryContent%3Dupload%26editor%3Dtinymce%26hidetb%3D1; wp-settings-time-47=1390228546; wp-settings-time-877=1392096718; wp-settings-time-2579=1393680813; wp-settings-time-2578=1393427211; wp-settings-time-106=1394689670; wp-settings-time-4965=1396012806; PHPSESSID=28tioc16rbc3314br3smf9djv7; wordpress_logged_in_3bbc4cdbbb4e6dcd108616247c041571=nirajmchauhan%40gmail.com%7C1403246168%7C08fbbba723e8d02b102a50fb5d0dee38; last_navigator_url=http%3A%2F%2Fsoller.local%2Fsite%2Fprofile%2Fmy-assessments%2F; url_route_slug=%2Fniraj; current_navigator_url=http%3A%2F%2Fsoller.local%2Fniraj
Connection: keep-alive
【问题讨论】:
【参考方案1】:您应该删除 [PT] 重写标志。 您可以在此处了解有关重写标志的更多信息:http://httpd.apache.org/docs/current/rewrite/flags.html#flag_pt
添加
此外,您可能需要在 wordpress 规则之前移动重写规则。您的代码将如下所示
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^about/?$ /site/about_us/ [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
【讨论】:
对不起,删除匹配字符串中的第一个斜杠 - 应该是:RewriteRule ^about/$ /site/about_us/ [L] 我刚刚做了,它正在工作:lovegracy.com/about - 屏蔽 url 现有文件:lovegracy.com/site/about_us 你遇到什么错误?如果您想在最后没有斜杠的 url 中使用它,请将匹配的字符串更新为:^about/?$ 重定向到什么网址 当点击此 URLhttp://soller.local/about/
时,它会重定向到 http://soller.local/site/about_us/
。尝试删除 about
之后的最后一个斜线,但没有用
这应该可以尝试检查您是否正在编辑正确的 htaccess 并查看是否有类似的重定向以上是关于Htaccess 规则给出 301 错误的主要内容,如果未能解决你的问题,请参考以下文章