1

How can I change url in this way using htaccess:

http://example.com/page.php?go=something.php

should be redirected to:

http://example.com/something

If the get parameter name is different than 'go' leave as it is...

2 Answers 2

2

This should do:

# Assuming that "RewriteEngine On" has already been called
RewriteCond %{QUERY_STRING} ^(.*&)?go=([a-z]+)\.php(&.*)?$
RewriteRule page.php %2?

What happens here? First, RewriteCond matches a query string that contains the go=something.php, where "something" is captured by ([a-z]+). Then the RewriteRule uses the second capture group's contents from RewriteCond, containing "something.php". The question mark at the end gets rid of the original query string.

Note: if you want to preserve the rest of the query string excluding go=... parameter, things get a bit more complicated.

See the docs in http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html for more info.

Sign up to request clarification or add additional context in comments.

Comments

1

something like this (google around for the correct syntax)

RewriteEngine On
RewriteBase /
RewriteRule ^page.php?go=login.php /login [L]

2 Comments

The downside of using this, page.php?something&go=login.php doesn't work, and it's still valid on page.php?go=login.phpjunk
google around for correct syntax and how to get around those problems. e.g. add $ after login.php to prevent login.phpjunk from triggering

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.