user1577333
user1577333

Reputation:

Apache Query String Rewrite

I'm trying to rewrite a query string in Apache.

The current (example) domain is: example.com/?domain=domain.com

I would like this to then be rewritten into: example.com/domain.com

So, when a user enters: example.com/?domain=domain.com

They are always redirected to the pretty version: example.com/domain.com

I've tried quite a few different rewrites, such as:

RewriteEngine On
RewriteRule ^([^/]*)$ /?domain=$1 [L]

But this fails to work (i.e. nothing happens) with .htaccess and ModRewrite enabled.

Any help would be greatly appreciated.

Upvotes: 0

Views: 2508

Answers (1)

Rajarshi Haldar
Rajarshi Haldar

Reputation: 111

Try this -

RewriteCond %{QUERY_STRING} ^domain=(.*)$
RewriteRule ^(.*)$ http://example.com/%1? [L]

Empty question mark at the end is important as it will discard the original query string.

Upvotes: 2

Related Questions