Question

I need to redirect an old dynamic page to a new keyword-url one:

Redirect 301 http://www.domain.com/index.php?id=100 http://www.domain.com/newhello

However, I keep getting a 404 error:

The requested URL /index.php was not found on this server.

It is as if apache is ignoring the query string and only looking at the 'index.php' part of the URL.

I've played around with 'RewriteRule' and 'RedirectMatch 301' too but have the same result. Any advice would be appreciated.

EDIT - below is a paste of the entire .htaccess file's contents. Note this is in the root directory:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !newroot/
RewriteRule (.*) /newroot/$1 [L]

#successful 301 redirect or mod_rewrite directives will be listed from here.
Was it helpful?

Solution

You cannot match QUERY_STRING using Redirect directive. Use mod_rewrite instead like this in your root .htaccess file:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^id=100$
RewriteRule ^index\.php$ http://www.domain.com/newhello? [L,R=301]

RewriteCond %{HTTP_HOST} ^(www.)?domain\.com$
RewriteCond %{REQUEST_URI} !/newroot/
RewriteRule (.*) /newroot/$1 [L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top