0

So currently I have URLs that looks like this:

http://localhost/?v=register
http://localhost/?v=profile&u=thatgerhard

I want the above to look like this:

http://localhost/register/ (without trailing /)
http://localhost/profile/thatgerhard/ (without trailing /)

I spent a ton of time trying to get this to work even though it seems like it should be a simple fix.

This is what I have atm:

RewriteBase /
RewriteEngine On

RewriteRule ^((.)*)$ /?v=$1&p=$

I would ideally like this to be dynamic so that if you do ?v=foo it will automatically do /foo/ without adding "foo" to the htaccess file.

Any help or direction will be greatly appreciated. :)

1 Answer 1

1

You should use RewriteCond Directive and RewriteCond backreferences. The %1 backreference matches the query string parameter v, the %2 backreference matches the query string parameter u. The RewriteRule redirects the request permanently and discard the query string entirely.

RewriteCond %{QUERY_STRING} ^v=([^&]*)$ [NC]
RewriteRule ^/?$ /%1/? [R=301,L]

RewriteCond %{QUERY_STRING} ^v=([^&]*)&u=([^&]*)$ [NC]
RewriteRule ^/?$ /%1/%2/? [R=301,L]
Sign up to request clarification or add additional context in comments.

Comments

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.