Forum Moderators: phranque
I got a problem with simple rewrite. I have got a site where users create their subdomains.
subdomain.domain.com
When they navigate through their website the address becomes:
subdomain.domain.com/menu
As I got the wildcard turned on, every request (like subdomain.domain.com/menu) is directed to root index.php file which serves the content - with help of simple rewrite:
RewriteRule ^([A-Za-z0-9-]+)/?$ /index.php
Now when the address becomes more complex:
subdomain.domain.com/menu/submenu
server directs me to a file which doesn't exist (submenu)
I tried adding another rewrite rule:
RewriteRule ^(.*)/(.*)?$ /index.php
but this one direct me to:
subdomain.domain.com/menu/subdomain.domain.com
instead of
subdomain.domain.com/menu/submenu
Could You please give me some information what am I doing wrong/and/or some tips on proper way to do this?
Don't use (.*) as a pattern to match - it grabs the whole string, and has to do hundreds of 'back off and compare' operations to find a match. Use ([^/]+) or ([^.]+) or somesuch instead.
It looks like there is interaction with some other rules somewhere to get that result. With a rewrite the URL seen in the browser should not change. If it changes it means you are being redirected. That means the rewrite process has failed.
I tried adding [L] to the end of every line, but still with no luck.
There is only one rewrite line + the second which I am trying to achieve subdomain.domain/menu/submenu to /index.php.
Ive noticed that with the rewrite line like:
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /index.php [L]
which is supposed to achieve the desired effect Firebug shows that there are two GETs
GET subdomain.domain.com/menu/submenu - 302 Found
but then it immidiatelly does another request
GET subdomain.domain.com/menu/subdomain.domain.com - 404
If You have any ideas please share.