문제

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.
도움이 되었습니까?

해결책

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]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top