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

http://www.batchheader.co.uk/knowledgebase.php?action=displayarticle&id=137

which redirects to:

http://www.batchheader.co.uk/knowledgebase/137/Why-is-my-secure-site-not-showing-the-padlock-in-the-browser.html

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”

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]
</IfModule>