mod rewrite - mod_Rewrite conditions and rules ( confused ) help please -
help please,
after numerous hours searching solution problem have become confused, appologies if been answered before.
i have current url :
i cleaning urls have created rewrite rule parse following previous url :
http://www.mydomain.com/dental_news/2968/redefining-oral-hygiene-intervention
the rule have used in .htaccess file below :
rewriterule ^dental_news/([^/]*)/([^/]*)$ /news/dentistry_dental/article_detail.php?article=$1&title=$2 [l] this working expected, however.. need have old url ( indexed on many search engines ) point new url 301 redirect.
i have tried numerous things of yet nothing errors, presume looping error have.
does out there have idea how can achieve 2 way redirect without looping?
any appreciated
edit
the above problem has been resolved, can see answer below, have query, should me in understanding whats going on hope :)
i have url www.mydomain.com/news/dentistry_dental/index.php want redirect 301 www.mydomain.com/dental_news/
i have tried rewriting code answer below fail, still lacking understanding of whole thing think.
any great :)
regards m
try following. first condition should protect redirect loop (it matches requests not beginning /dental_news. %1 , %2 match corresponding regex groups previous rewritecond. also, trailing ? on rewriterule, remove querystring on redirect.
rewritecond %{request_uri} !^\/dental_news\/ rewritecond %{query_string} article=([0-9]*)&title=(.*)$ rewriterule (.*) /dental_news/%1/%2? [l,r=301] hope helps.
edit: changed last group of second rewritecond match until $ of $fr=1, if intended &1, can change end of rewritecond group ([^&]*) instead.
rewritecond %{request_uri} !^\/dental_news\/ rewritecond %{query_string} article=([0-9]*)&title=([^$]*)$ rewriterule (.*) /dental_news/%1/%2? [l,r=301] edit:
rewriteengine on rewriterule ^dental_news/([^/]*)/([^/]*)$ news/dentistry_dental/article_detail.php?article=$1&title=$2&redirect [l] rewritecond %{request_uri} !^/dental_news/ rewritecond %{query_string} article=([0-9]*)&title=([^&]*)$ rewriterule (.*) /dental_news/%1/%2? [l,r=301]
Comments
Post a Comment