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...
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...
something like this (google around for the correct syntax)
RewriteEngine On
RewriteBase /
RewriteRule ^page.php?go=login.php /login [L]
if(!empty($_GET['go']) && is_string($_GET['go']) && $_GET['go'] == 'login.php'){
header('Location: /login');
exit;
}
Remember: no output (cookies, html) before this.
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.