Forum Moderators: phranque

Message Too Old, No Replies

Help with a RewriteRule

I'd like URLs that refer to a subdir to be ignored

         

danielkun

1:33 pm on Feb 9, 2010 (gmt 0)

10+ Year Member



I am using the following Rewrite rule in .htaccess to rewrite URLs that refer to .html files.

RewriteRule ^(.+)\.html$ /web/index.php?page=$1 [L]


However, this rule also rewrites URL's referring to subdirectories like "www.example.com/dir/file.html".
How would I rewrite it to ignore an .html file if it is located in a subdir? (I suppose the only way is it to look for a forward slash, but I can't seem to get it to work)

edit.
I may actually answer my own question here. The following seems to work fine. Although I'm not sure if this is the "correct" way to do it.

RewriteCond $1 !^(.+/)
RewriteRule ^(.+)\.html$ /web/index.php?page=$1 [L]

jdMorgan

2:49 pm on Feb 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You only need one line:

RewriteRule ^([^/]+)\.html$ /web/index.php?page=$1 [L]

Jim

danielkun

3:30 pm on Feb 9, 2010 (gmt 0)

10+ Year Member



Thank you