Link to home
Start Free TrialLog in
Avatar of cortdev
cortdev

asked on

.htaccess rewrite

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.
Avatar of Ian Gough
Ian Gough
Flag of United Kingdom of Great Britain and Northern Ireland image

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

ASKER CERTIFIED SOLUTION
Avatar of syedyounus
syedyounus
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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