We would like to shorten our affiliate links on our site to make them look nicer. How would we shorten this: http://www.domain.com/index.php?name=abc123 to example, this: http://www.domain.com/?abc123 so that instead of affiliates giving out this link http://www.domain.com/index.php?name=abc123 they could give out this one instead: http://www.domain.com/?abc123 Thanks.
Found this using google... RewriteEngine on RewriteRule ^([^/\.]+)/?$ /index.php?name=$1 [L] Code (markup): This will rewrite this URL: http://www.domain.com/index.php?name=abc123 to this URL: http://www.domain.com/abc123
Thanks Krnl! It works, but we need to have something before that, because if an affiliate username is "images" then that messes up the whole deal. As it then sends the users to the images folder. So I though I would make: http://www.domain.com/index.php?name=abc123 direct to this URL: http://www.domain.com/aff/abc123 However when changing: it didn´t work out. I really need to read a book on Apache thanks
It just needs to be the other way around: RewriteRule ^aff/([^/\.]+)/?$ /index.php?name=$1 [L] Code (markup):
Pondlife: Good point! I don´t really want a question mark in my new sexy URL. I tried this: RewriteRule ^aff/([^/\.]+)/?$ /index.php?name=$1 [L] To make www.domain.com/aff/user123 go to www.domain.com/index.php?name=user123 But without luck. What´s going on?
That's strange. It should work like that. You do still have the RewriteEngine On line in the .htaccess file ? If so, check that you also have AllowOverride All in your main httpd.conf. If you have something like AllowOverride None then .htaccess files won't work at all. After that, try adding [R] into the rewrite rule so that it ends with [R,L]. This will cause a redirect to happen which will change the URL. That way we will know that the rewrite engine is definitely on and we will also know what the URL is being changed into.