tags:

views:

1882

answers:

4

Ok, im pretty new at this and I would really appreciate some help, thanks!

How can i rewrite this in .htaccess correctly?

So I have a query string in my url:

/?url=contact

All i want to do is remove the query string

/contact

Help? I scoured google and I'm learning the syntax right now, but the fact remains..I dont know how to do it just yet. Thanks to all

+1  A: 
RewriteCond %{QUERY_STRING} url=(.*)
RewriteRule index.html  %1

(or whatever if it's not index.html, index.php, whatever)

You need to capture the query string, which is not looked at by RewriteRule normally, and use the %1 back reference, not $1 as you would in a capture in a RewriteRule

Devin Ceartas
A: 

No that didnt work ;/

wes
Instead of leaving another answer, it's best if you update your question or comment on the answers that have been provided.
random
+4  A: 

Try this:

RewriteEngine On
RewriteRule ^(.*)$ /index.php?url=$1 [L]

To a user on your site, they will see and navigate to this:

http://example.com/contact

But the real page would be something like this:

http://example.com/index.php?url=contact

This bit, [L], tells the server that this is the last line of the rewrite rule and to stop.

random
I don't think you want the R=301 in the flags. That will cause the browser to actually redirect (re-request) the new url (/index.php?url=...) instead of just doing an internal rewrite.
Brenton Alker
Quite right on the 301, fixed up the flags to stop where it's needed
random
A: 

RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]

IRC FTW, Thanks all for the input!

wes