Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite problem

simple rewriterule - doesn't work when things become more complex

         

malina

12:21 am on Mar 6, 2009 (gmt 0)

10+ Year Member



Hi!

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?

g1smd

12:30 am on Mar 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Add [L] to the end of every rule.

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.

malina

10:15 pm on Mar 6, 2009 (gmt 0)

10+ Year Member



Thank You for the reply.

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.

jdMorgan

11:07 pm on Mar 6, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You code does not generate a 302 redirect, or any other redirect. Your code only does an internal rewrite. Look for the problem elsewhere -- Either in your server configuration, or in your script.

Jim