jnroche
jnroche

Reputation: 115

.htaccess rewriting url from subdirectory

I have entries in my .htaccess that goes like this:

RewriteRule ^$ dubai/ [R]
RewriteRule ^dubai/$ page/index.php [L]
RewriteRule ^$ pakistan/ [R]
RewriteRule ^pakistan/$ page/index.php [L]

basically I want to make a rule that can handle countries as part of the rewrite, the above code i have is redundant and can cause the file to grow unnecessarily.

Is there a way to automatically redirect the page to page/index.php if it serves for any countries? I tried putting this line to the last line above:

RewriteRule ^([a-zA-Z\/]*)/$ page/index.php

My problem is it no longer reads the succeeding rules for the other pages to serve. The below lines are samples of the rules just below the last one above:

RewriteRule ^([a-zA-Z\/]*)rent/$ page/index.php?methodcall=rent&for=Rent
RewriteRule ^([a-zA-Z\/]*)landlords/$ page/index.php?methodcall=landlords

What happens is the get vars are no longer read by index.php file, if i remove the last rewriterule the key vars are read properly.

Any suggestions?

Thanks in advance!

Upvotes: 1

Views: 183

Answers (1)

Book Of Zeus
Book Of Zeus

Reputation: 49867

Try this:

RewriteEngine on

RewriteRule ^([a-z]+)(\/?)$ page/index.php [NC,QSA,L]
RewriteRule ^([a-z]+)/rent(\/?)$ page/index.php?methodcall=rent&for=Rent [NC,QSA,L]
RewriteRule ^([a-z]+)/landlords(\/?)$ page/index.php?methodcall=landlords [NC,QSA,L]

Upvotes: 4

Related Questions