I am trying to write .htacces rewrite rules for blog module.
if => www.xyz.com/index.php It should not redirect anything
if => www.xyz.com/contactus.php It should not redirect anything
but
if => www.xyz.com/blogs/test-string1-and-string2
(URL pattren fixed for blog pages)
It should redirect to blog_details.php?id=$1
I have tried following rules.:
RewriteCond %{HTTP_HOST} !/blog/
RewriteRule blogs/(w+) blog_details.php?id=$1 [NC]
This is not perfect rule. It is causing problems while generating sitemaps and Seo results.
I want some strong validation for URL like .php at the end of URL or
words separated by hyphen (-) after blog/. Then I can redirect url.
2
Answers
First you need not check the
HTTP_HOST
here, as you are not changing it.If you do, you should compare it to a possible Hostname, not to a possible URL, i.e.
To check, if the URL does not end in “.php” and contains hyphens, this should be a possbility
Following rule should work for you: