user6043723
user6043723

Reputation: 177

.htaccess - Redirect specific page with php parameters

I have the following url http://mywebsite.com/browse-test.php?v=myname

I want it to be redirected to this instead http://mywebsite.com/myname

This is what I tried so far

RewriteEngine On
RewriteCond %{HTTP_HOST} mywebsite.com/browse-test.php?v=$ [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [L,R=302]

When I looked for an answer on this website and google I didn't find any examples that made a redirect based on on a specific file and php url paramater.

Upvotes: 0

Views: 232

Answers (1)

Panama Jack
Panama Jack

Reputation: 24448

This code should help.

RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /+browser-test\.php\?v=([^&\s]+)
RewriteRule ^ /%1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /browse-test.php?v=$1 [L]

Having a look at the mod_rewrite docs to get a better understanding as MrTux noted is highly suggested to better understand the different options.

Upvotes: 1

Related Questions