views:

870

answers:

3

Hi, I have a url like this.

/domains/details.php (NOTE: domains is dynamic and can be anything)

How do I remove the domains part from the URL using .htaccess so the actual lookup is:

/details.php

OR it'll be cool if I can get domains into the URL. /details.php?page=domains

Thanks! Scott

A: 

you're going to need the rewrite engine in apache.

here's a good tutorial to get you started.

contagious
+4  A: 
RewriteEngine on
RewriteBase /

RewriteRule ^([^/]+)/details.php$ /details.php?page=$1 [R=301]

Leave off the [R=301] if you want an internal redirect rather than an actual HTTP redirect.

To preserve existing query parameters you can change the rule to this:

RewriteRule ^([^/]+)/details.php(.*)$ /details.php?page=$1&%{QUERY_STRING} [R=301]
Laurence Gonsalves
Hey SUPER thanks a lot for the answer!
That's brilliant!! Thanks so much!!!
+1  A: 

Please try to use the following rules to deal with your last request:

RewriteRule ^(?!domains/.*)([^/]+)/details.php$ domains/details.php?page=$1 [R=301,QSA]
RewriteRule ^domains/details.php$ details.php [NC,L]
TonyCool
Hi Tony, thanks for the reply. The "domains" part is dynamic. Would this htaccess work with that?Thanks so much!
Ok, then is there any dependency between "domains" and "domains1" values in your explanation or they may be completely different?
TonyCool