2

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

4
  • @Lawrence: Thanks!! One quick edit to the above. What if the URL was mydomain.com/domains/details.php?user_id=2323 How would the rewrite rule work in that case if I want to capture the URL parameter for user_id (and it is a dynamic variable). Thanks!! Commented Jul 17, 2009 at 4:02
  • I updated my answer to include preserving the existing query parameters. Commented Jul 17, 2009 at 4:51
  • @Laurence: Hey thanks so much for the help! Works!!! Commented Jul 17, 2009 at 5:16
  • @Laurence.. have another tough one. Tried googling but no luck. Maybe you can help. See comments under your answer. Commented Jul 17, 2009 at 6:08

2 Answers 2

5
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]
Sign up to request clarification or add additional context in comments.

Comments

1

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]

2 Comments

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?