这就是我的htaccess的样子:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.site.com$ [NC]
RewriteRule .? http://site.com%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} /page1/([^?].*)$ [NC]
RewriteRule /page1/(.*)$ /page1/?$1 [L] # change /page1/stuff to /page1/?stuff
# End rewriting for page1
RewriteCond %{REQUEST_URI} /page2/([^?].*)$ [NC]
RewriteRule /page2/(.*)$ /page2/?$1
# End rewriting for page2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://%{HTTP_HOST}/$1 [R=301,NS,L]
Options -Indexes
我还想要的是,如果用户转到site.com/page1/stuff
或site.com/page1/stuff/more
,它会在地址栏中添加一个尾部斜杠,并将其更改为site.com/page1/stuff/
和{{ 1}}但我没有尝试过。有没有办法在不引起重定向循环的情况下执行此操作?
我希望我的所有网址都有一个尾部斜杠,我看到目录已经在做了。
编辑:为了澄清,我希望用户可以看到尾部斜杠,而不是site.com/page1/stuff/more/
答案 0 :(得分:0)
感谢@LazyOne链接,无论如何这都有效:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]