2

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/login
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]
leppie
  • 115,091
  • 17
  • 196
  • 297
tdurham
  • 311
  • 1
  • 4
  • 6

1 Answers1

2

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]
akond
  • 15,865
  • 4
  • 35
  • 55
  • got it! So, in this case, the slash is required on the end to make the source different from the target. And would seem that the only way around this would be to pick a different source name... since the target can't change. – tdurham Jan 20 '11 at 07:44
  • Just add RewriteCond as in my example in front of your rule. – akond Jan 20 '11 at 07:46