Forum Topic: Rewrite and not have old url accessible

Forum: .htaccess Forum : Redirecting • Posted by Neil Batchelor • Updated:

I am having an issue where the rewrite that I have in place is working but the old url is still accessible. I wish to only have the the rewritten new SEO url viewable.

I have a URL

which redirects to:

The redirect code I a using is:

# Knowledgebase
RewriteRule ^knowledgebase/([0-9]+)/[a-z0-9_-]+\.html$ ./knowledgebase.php?action=displayarticle&id=$1 [L,NC]
RewriteRule ^knowledgebase/([0-9]+)/([^/]*)$ ./knowledgebase.php?action=displaycat&catid=$1 [L,NC]
RewriteRule ^knowledgebase$ ./knowledgebase.php [L,NC]

1 Reply to “Rewrite and not have old url accessible”

Jeff Starr
Posted by Jeff Starr

It looks like you are trying to target the query string, so maybe just add some rewrite conditions to let the rules know about it; otherwise, they are looking at the URL request. So for example something like this:

<IfModule mod_rewrite.c>
	RewriteCond %{QUERY_STRING} ^knowledgebase$ [NC]
	RewriteRule .* /knowledgebase.php [R=301,L]