We help IT Professionals succeed at work.

.htaccess rewrite

Last Modified: 2012-05-09
Hello guys, I'm trying to redirect some pages which address are:


For some reason because the extension is .html the redirect does not work with the complete string so I redirected example.html to index.php and it worked but now here is the problem:

If you go to  example.html?id=7 you get index.php?id=7 or
if you go to example.html?id=17 you get index.php?id=17.

My question is:
-How can I redirect example.html?id=7 to /example/address and make it work.
-If that is not possible how can I make example.html?id=7 go to index.php and loose all of the extra strings.
Watch Question

Something like the below should do it for you,
RewriteCond %{QUERY_STRING} ^id=7$
RewriteRule (.*) http://www.yourdomain.com/index.php?id=7? [R=301]

RewriteCond %{QUERY_STRING} ^id=14$
RewriteRule (.*) http://www.yourdomain.com/index.php?id=14? [R=301]

Open in new window

This one is on us!
(Get your first solution completely free - no credit card required)
Ok after looking again the below should and i have tested it on my site redirect whatever id to index.php?=whateverid
RewriteCond %{QUERY_STRING} ^id=([0-9]+) 
RewriteRule (.*) http://www.yourdomain.com/index.php?=id%1 [R=301]

Open in new window

Or here's a little shortcut to be placed on index.php
As you said:
If you go to   example.html?id=7 you get index.php?id=7
if you go to  example.html?id=17 you get index.php?id=17

Codes below ...

// put on index.php
if ( isset($_GET['id']) ) {
	header("Location: index.php");

Open in new window

Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.