Ad

RewriteRule Does Not Match If Folder Name Set To "myfolder/"

Since we migrated to a new server, some of our pages are broken (404). Reason is we have 2 broken rewrite rules. What's really strange is that they work if I change folder's name. For example this work:

RewriteRule ^anything/([a-zA-Z0-9-]+)/$ page.php?var=$1 [L]

This doesn't:

RewriteRule ^myfolder/([a-zA-Z0-9-]+)/$ page.php?var=$1 [L]

I can't even find a trick to make 301 redirects, because my original "myfolder/" virtual folder never matches.

Any ideas what's going on? I was thinking it could be a rule override or something like that (as it's hosted on a multidom solution), but i don't have such rules in my main site at the root. It drives me crazy. Thx!

Ad

Answer

In practice you probably want to do 2 things. Disable multiviews and also bypass rules if the request is a real directory.

Options -MultiViews #turn off automatic URI matching, can cause weirdness
RewriteEngine on

#stop here if the request is a real file or directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^myfolder/([a-zA-Z0-9-]+)/?$ /page.php?var=$1 [L]
Ad
source: stackoverflow.com
Ad