部队尾随斜线重写查询字符串的结尾 [英] Force trailing slash at end of rewritten query string

查看:122
本文介绍了部队尾随斜线重写查询字符串的结尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的htaccess的样子:

Here's what my htaccess looks like:

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/东东/多这将增加一个斜线在地址栏中并将其更改为 site.com/page1/stuff / site.com/page1/stuff/more / ,但没有我想的作品。有没有办法做到这一点,而不会导致重定向循环?

What I also want is to have it that if a user goes to site.com/page1/stuff or site.com/page1/stuff/more it will add a trailing slash in the address bar and change it to site.com/page1/stuff/ and site.com/page1/stuff/more/ but nothing I tried works. Is there any way to do this without causing a redirect loop?

我希望所有我的网址有一个结尾的斜线,我看到已经这样做。目录

I want all my urls to have a trailing slash and I see directories already doing that.

编辑:为了澄清,我想最后的斜线是对用户可见的,而不是

To clarify, I want the trailing slash to be visible to the user but not the ?

推荐答案

感谢该链接的@LazyOne,反正这个作品:

Thank for that link @LazyOne, anyway this works:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

这篇关于部队尾随斜线重写查询字符串的结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆