I want to change my website\'s dynamic urls to Search Engine Friendly URL\'s
Now the urls like this www.website.com/news.php?id=127591 , I want it became this www.websit
Please try this rule in your .htaccess file:
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteCond %{THE_REQUEST} \?id=([0-9]+)\s [NC]
RewriteRule ^news\.php /news/%1? [R=301,L]
RewriteRule ^news/([0-9]+) /news.php?id=$1 [L,NS,NE,QSA,NC]
Inside news.php
when URL doesn't have /some-title
then output this META tag to stop indexing /news/987
type URIs:
<meta name="robots" content="NOINDEX, NOFOLLOW">
Once you notice URI of /news/987/some-title
inside news.php
simply mask above META tag.
I have tested it and seems to be working fine so let me know if doesn't work for you.
simplest answer just add a canonical link in your head of your html document, this will stop your duplicate content issue.
If you're only concerned about search engines, you could create a robots.txt file containing:
User-agent: *
Disallow: /news.php
This will make sure that search engines don't follow the news.php links.
To fix your rewrite rules, you might try adding L
to the first RewriteRule
to make sure that mod_rewrite doesn't continue:
RewriteRule ^news/([0-9]+) /news.php?id=$1 [PT,L]
RewriteCond %{QUERY_STRING} ^id=([0-9]+)
RewriteRule ^news\.php /news/%1? [R=301,L]
If [L]
doesn't work for you, the issue might be separate internal requests (not sub-requests that you could halt with [NS]
).
See here.
try using L
[L]
instead of
[PT]
You need to inspect the URI in the HTTP request line (i.e. %{THE_REQUEST}
) as the other could already have been rewritten (like in your case):
RewriteCond %{THE_REQUEST} ^GET\ /news\.php\?
RewriteCond %{QUERY_STRING} ^id=([0-9]+)
RewriteRule ^news\.php /news/%1? [R=301,L]