将非斜杠URL定向为斜杠 [英] Directing Non-Slash URL to Slash
本文介绍了将非斜杠URL定向为斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我输入 website.com/seo
链接时,我想进行301重定向到 website.com/seo/
链接.但是,我不希望它在我在当前htaccess中编写的代码中被破坏.
When I enter the website.com/seo
link, I want to make a 301 redirect to the website.com/seo/
link. However, I don't want it to be broken in the codes I wrote in the current htaccess.
我的htacces代码:
my htacces codes:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
推荐答案
仅使用其中之一,请勿一起使用!
尝试:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^\/(.*?)\/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
如果这不起作用,请使用:
If that doesn't work, use:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^\/(.*?)\/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]
删除以前的规则,然后尝试一次.如果在删除以前的规则后仍然有效,请告诉我.
Remove the previous rules, and try once. If it works after removing previous rules, then let me know.
这篇关于将非斜杠URL定向为斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文