开发者

RewriteRule optional trailing slash issues

Working on an application that I’m building in parallel to a wordpress site with permalinks turned on. So, there are other rewrites later in the htaccess that handle the catch-all aspects for wordpress. But, I’m attempting to perform some of my own rewrites before it gets to those. - and of couse using [L] after mine. Everything is working perfect until I try to add the option to the end allowing a slash or no slash (and still make a match).

Here’s an example of what throws a 500 error on this server:

RewriteRule ^app/([^/]+)/?$ /app/$1\.php [L,QSA]

http://<domain>.com/app/lo开发者_运维问答gin
or
http://<domain>.com/app/login/

But the following works just fine, and is above the previous example in the htaccess.

RewriteRule ^app/p/([^/]+)/?$ /app/page.php?page_slug=$1 [L,QSA]

http://<domain>.com/app/p/styles
or
http://<domain>.com/app/p/styles/

I've tried variations with little/no success.

RewriteRule ^app/([^/]+)/{0,1}$ /app/$1\.php [L,QSA]
and
RewriteRule ^app/([^/]+)[p]/[\p]?$ /app/$1\.php [L,QSA]


This is because your target location /app/$1.php is perfectly matched for your source location ^app/([^/]+)/?$. So the page getting redirected to itself.

RewriteCond %{REQUEST_URI} !\.php
RewriteRule ^app/([^/]+)/?$ /app/$1.php [L,QSA]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜