Reputation: 598
I trying to write "rewriting rule" in .htaccess file
I have php file on my server by name go.php
This file is use to forward/redirect to provided url/link
For example: mydomian.com/go.php?url=http://www.google.com/
It works perfect but I want to make it like mydomain.com/?http://www.google.com/
my htaccess code
RewriteRule ^/(.*)$ go.php?url=$1 [L,QSA]
This one does not work then I tried
RewriteRule ^/?(.*)$ go.php?url=$1 [L]
Upvotes: 1
Views: 77
Reputation: 784918
You can use this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} .+
RewriteRule ^/?$ go.php?url=%{QUERY_STRING} [L]
QUERY_STRING
is automatically carried forwarded to new URI.
Upvotes: 1
Reputation: 33
The problem with the second one is that the question mark is a Regex special character that effectively means "if it exists." So the second example won't work because it's saying that the URI could start with a slash.
This is untested, but I think it should be as simple as escaping the question mark so that it's viewed as a character. Like so:
RewriteRule ^/\?(.*)$ go.php?url=$1 [L]
Note the extra slash before the question mark which identifies it as a string and not a special character.
Upvotes: 0