Need advice and Help

New to mod_rewrite? This is a good place to start.

Need advice and Help

Postby wendy » Tue Dec 13, 2005 10:19 pm

Hi guys,

I'm a newbie to mod rewrite, so pardon me please.
I'm learning mod rewrite by trial and error (plus searching), and it's fun, even though sometimes it's so stressful.

So anyway, here is my rewrite rule
Code: Select all
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]
RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com:80$
RewriteRule ^$ index.php?q=domain.com/ [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com:80$
RewriteRule ^domain\.com/(.*)$ index.php?q=domain.com/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com:80$
RewriteRule ^(.*)$ index.php?q=domain.com/$1 [L,QSA]


It works as what I want it to be.
The first two lines will solved the permanent redirection of 'domain.com' to 'www.domain.com'. The rest of the code do the logic.

So basically the index.php will receive a parameter 'q' to get the right host.
The first rewrite rule after the permanent redirection is sending the domain.com to index.php?q=domain.com. The second rewrite rule is sending all the domain.com/domain.com/* request to index.php?q=domain.com/*. The third rewrite rule is sending all the domain.com/* request to index.php?q=domain.com/*.

The second rule is needed to prevent the third rule addind a duplicate domain.com in parameter 'q'.

NOW, my question is, is there anyway to shorten this out? I still think that there has to be a better way to make this shorter and simple.

Another thing, I added a nother querystring called 'lang'. Is it possible to add another rewrite rule to this rule?

For example, domain.com/lang-en will be directed to index.php?q=domain.com&lang=en
The path has to be start 'lang-' and followed by 2 letters. I'm confuse on how to match this new rule with the one that I have right now.

Any helps will be really appreciated.

Thanks


Regards,
Wendy Novianto[/code]
wendy
 
Posts: 1
Joined: Tue Dec 13, 2005 10:06 pm

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 11 guests

cron