We help IT Professionals succeed at work.

.htaccess rewrite

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

example.html?id=7
example.html?id=14
example.html?id=17
example.html?id=6

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.
Comment
Watch Question

Something like the below should do it for you,
Ian
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)
UNLOCK SOLUTION
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
or
if you go to  example.html?id=17 you get index.php?id=17


Codes below ...

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

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.

OR

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.