mod_rewrite trailing slash with RewriteCond

被刻印的时光 ゝ 提交于 2020-01-02 08:32:53

问题


I have searched through the related mod_rewrite qustions but I can't anything specific enough so I'll post:

Heres my rule that adds a trailing slash:

RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]

Only I want to exclude one specific directory eg. /mydirectoryname/ and not add the trailing slash to anything that starts with that. Reason being its breaking some of my ajax calls.


回答1:


Add another RewriteCond:

RewriteCond %{REQUEST_URI} !/mydicrectoryname)/




回答2:


You can descibe that with just one condition:

RewriteCond $0 !^mydirectoryname(/|$)
RewriteRule ^[^\.]+[^/]$ /$0/ [R=301,L]


来源:https://stackoverflow.com/questions/1859536/mod-rewrite-trailing-slash-with-rewritecond

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!