0

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.

4
  • 1
    Your RewriteCond can never be true. See httpd.apache.org/docs/current/mod/mod_rewrite.html Commented Aug 14, 2016 at 22:16
  • Hi, How do I go about it please as I'm not familiar with apache? Commented Aug 14, 2016 at 22:21
  • Do you want just this file browse-test.php to redirect to mywebsite.com/myname? Commented Aug 14, 2016 at 23:06
  • I'd like all mywebsite.com/browse-test.php?v=myname to redirect to mywebsite.com/myname please Commented Aug 14, 2016 at 23:17

1 Answer 1

1

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.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.