简体   繁体   English

301重定向以摆脱斜线

[英]301 redirect to get rid of the slash

Is there a way in htaccess to redirect all the pages from / to nothing. 在htaccess中是否有办法将所有页面重定向到/没有任何内容。 So for example i want this 所以例如我想要这个

http://somesite.com/something/ ==> http://somesite.com/something
http://somesite.com/another_thing/ ==> http://somesite.com/another_thing
http://somesite.com/page3/ ==> http://somesite.com/page3
http://somesite.com/page4/ ==> http://somesite.com/page4

page3, page4, something, another_thing are all directories with an index.php file in each... and this is how i handled it page3,page4,something,another_thing都是每个目录中都有一个index.php文件......这就是我处理它的方式

in my htaccess i am getting rid of the / by this 在我的htaccess中,我正在摆脱/由此

DirectorySlash Off
RewriteCond %{REQUEST_FILENAME}/index\.php -f 
RewriteRule ^(.+)$ /$1/index.php [NC,QSA,L]

I basically want to 301 redirect just for seo reasons so everybody ends up on the non slash pages even if they are cached.thanks in advance 我基本上只是因为seo原因而想要301重定向,所以即使它们被缓存,每个人都会在非斜杠页面上结束。提前知道。

this 这个

If you want to remove trailing slashes from all requests that have them, try: 如果要从包含它们的所有请求中删除尾部斜杠,请尝试:

RewriteRule   ^/(.+)/$  /$1   [R]

See as well URL Rewriting Guide and look for Canonical URLs . 请参阅URL重写指南并查找Canonical URL Additionally please be aware of the documentation and security warning for the DirectorySlash Off directive . 此外,请注意DirectorySlash Off指令的文档和安全警告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM