Php 如何从mod rewrite中放入尾部斜杠

Php 如何从mod rewrite中放入尾部斜杠,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我在使用此重写时遇到问题: RewriteCond %{HTTP_HOST} www.example.com$ RewriteRule ^(.*)$ http://example.com$1 [R=301,L] 删除www url的步骤 但是返回的是一个没有尾部斜杠的url。例如:example.com/subfolder,它的url应该是example.com/subfolder,,但结果是example.com/subfolder,它会破坏url。有人能帮我解决这个问题吗?非常感谢 编辑

我在使用此重写时遇到问题:

RewriteCond %{HTTP_HOST} www.example.com$
RewriteRule ^(.*)$ http://example.com$1 [R=301,L] 
删除www url的步骤

但是返回的是一个没有尾部斜杠的url。例如:example.com/subfolder,它的url应该是example.com/subfolder,,但结果是example.com/subfolder,它会破坏url。有人能帮我解决这个问题吗?非常感谢

编辑:这是我的全部.htaccess

Header unset Pragma
FileETag None
Header unset ETag

# 1 YEAR
<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 2 DAYS 172800
<FilesMatch "\.(xml|txt|css|js)$">
Header set Cache-Control "max-age=604800, proxy-revalidate"
</FilesMatch>
# 1 MIN
<FilesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=60, private, proxy-revalidate"
</FilesMatch>

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Thu, 15 Dec 2011 20:00:00 GMT"
</FilesMatch>

RewriteEngine On

RewriteCond %{QUERY_STRING} (^|\?)f=([0-9]+)&t=([0-9]+)($|&)
RewriteRule ^viewtopic\.php$ /index.php?threads/%3/ [R=301,L]

RewriteCond %{QUERY_STRING} (^|\?)f=([0-9]+)($|&)
RewriteRule ^viewforum\.php$ /index.php?forums/%2/ [R=301,L]

RewriteCond %{HTTP_HOST} www.example.com$
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L] 

# Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php
#
# Uncomment the statement below if you want to make use of
# HTTP authentication and it does not already work.
# This could be required if you are for example using PHP via Apache CGI.
#
## EXPIRES CACHING ##

<IfModule mod_expires.c>

# Enable expirations
ExpiresActive On

# Default directive
ExpiresDefault "access plus 1 month"

# My favicon
ExpiresByType image/x-icon "access plus 1 yearâ€

# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"

# CSS
ExpiresByType text/css "access 1 monthâ€

# Javascript
ExpiresByType application/javascript "access plus 1 year"

</IfModule>

## EXPIRES CACHING ##
#<IfModule mod_rewrite.c>
#RewriteEngine on
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#</IfModule>

<Files "config.php">
Order Allow,Deny
Deny from All
</Files>

<Files "common.php">
Order Allow,Deny
Deny from All
</Files>
DirectoryIndex portal.php index.php index.html index.htm

RewriteCond %{HTTP_REFERER} !^http://example.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://example.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com$      [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]


# Start CloudFlare:example.com rewrite. Do not Edit 
RewriteCond %{HTTP_HOST} ^example.com 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 
# End CloudFlare rewrite. 


#   Mod_security can interfere with uploading of content such as attachments. If you
#   cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
#   SecFilterEngine Off
#   SecFilterScanPOST Off
#</IfModule>

ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 405 default
ErrorDocument 406 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 503 default

<IfModule mod_rewrite.c>

#   If you are having problems with the rewrite rules, remove the "#" from the
#   line that begins "RewriteBase" below. You will also have to change the     path


#   This line may be needed to enable WebDAV editing with PHP as a CGI.
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule     ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>
标题未设置Pragma
FileTag无
标题未设置ETag
#一年
标题集缓存控制“最大年龄=29030400,公共”
#1周
标题集缓存控制“最大年龄=604800,公共”
#2天172800
标题集缓存控制“最大年龄=604800,代理重新验证”
#1分钟
标头集缓存控制“最大年龄=60,专用,代理重新验证”
标题集过期“2011年12月15日星期四20:00:00 GMT”
重新启动发动机
重写cond%{QUERY\u STRING}(^ |\?)f=([0-9]+)&t=([0-9]+)($|&)
重写规则^viewtopic\.php$/index.php?线程/%3/[R=301,L]
重写cond%{QUERY\u STRING}(^ |\?)f=([0-9]+)($|&)
重写规则^viewforum\.php$/index.php?forums/%2/[R=301,L]
重写cond%{HTTP_HOST}www.example.com$
重写规则^(.*)$http://example.com/$1[R=301,L]
#使用PHP5.4 Single php.ini作为默认值
AddHandler应用程序/x-httpd-php54s.php
#
#如果要使用,请取消注释下面的语句
#HTTP身份验证,但它尚未工作。
#例如,如果您通过ApacheCGI使用PHP,则可能需要这样做。
#
##过期缓存##
#启用过期
过期于
#默认指令
ExpiresDefault“访问加1个月”
#我的favicon
ExpiresByType图像/x图标“访问加1年”
#图像
ExpiresByType image/gif“访问加1个月”
ExpiresByType图像/png“访问加1个月”
ExpiresByType图像/jpg“访问加1个月”
过期按类型图像/jpeg“访问加1个月”
#CSS
ExpiresByType文本/css“访问1个月”
#Javascript
ExpiresByType应用程序/javascript“访问加1年”
##过期缓存##
#
#重新启动发动机
#重写规则。*-[E=HTTP\U授权:%{HTTP:AUTHORIZATION},L]
#
命令允许,拒绝
全盘否定
命令允许,拒绝
全盘否定
DirectoryIndex portal.php index.php index.html index.htm
重写cond%{HTTP_REFERER}^http://example.com/.*$[NC]
重写cond%{HTTP_REFERER}^http://example.com$[NC]
重写cond%{HTTP_REFERER}^http://www.example.com/.*$[NC]
重写cond%{HTTP_REFERER}^http://www.example.com$[NC]
重写规则。*\(jpg | jpeg | gif | png | bmp)$-[F,NC]
#启动CloudFlare:example.com重写。不编辑
RewriteCond%{HTTP_HOST}^example.com
重写规则^(.*)$http://www.%{HTTP_HOST}/$1[R=301,L]
#结束CloudFlare重写。
#Mod_安全性可能会干扰附件等内容的上载。如果你
#无法附加文件,请从下面的行中删除“#”。
#
#分离过滤器发动机关闭
#secfilters可以关闭
#
错误文档401默认值
错误文档403默认值
错误文档404默认值
ErrorDocument 405默认值
错误文档406默认值
ErrorDocument 500默认值
错误文档501默认值
ErrorDocument 503默认值
#如果您对重写规则有问题,请从中删除“#”
#从下面的“重写基”开始的行。您还必须更改路径
#使用PHP作为CGI进行WebDAV编辑可能需要这一行。
#重写规则。*-[E=HTTP\U授权:%{HTTP:AUTHORIZATION}]
RewriteCond%{REQUEST_FILENAME}-f[或]
RewriteCond%{REQUEST_FILENAME}-l[或]
RewriteCond%{REQUEST_FILENAME}-d
重写规则^.*$-[NC,L]
重写规则^(data/| js/| style/| install/| favicon\.ico | crossdomain\.xml | robots\.txt)-[NC,L]
重写规则^.*$index.php[NC,L]

Uhm…只需在
.com
$1
之间添加一个
/
,如
http://example.com/$1
我尝试添加/但现在它返回重定向循环。我在上面的帖子中添加了我的htaccess代码。但是你的
www
规则不在你的
.htaccess
中。你最初在问题中使用的规则不在你的
.htaccess
文件中。您似乎已经删除了它,现在我们不知道它在哪里。顶部的规则将从
www.example.com
重写为
example.com
,并且有一个通用的cloudflare规则将从
example.com
重写为
www.example.com
,从而实现您的循环