.htaccess - htaccess 301 redirection using regular expression -
this current .htaccess file
rewritecond %{request_filename} !-f rewritecond %{request_uri} !(.*)/$ rewriterule ^(.*)$ $1/ rewriterule ^([^/]+)/$ index.php?p1=$1 [l] rewriterule ^([^/]+)/([^/]+)/$ index.php?p1=$1&p2=$2 [l] rewriterule ^([^/]+)/([^/]+)/([^/]+)/$ index.php?p1=$1&p2=$2&p3=$3 [l] rewriterule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ index.php?p1=$1&p2=$2&p3=$3&p4=$4 [l] rewriterule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ index.php?p1=$1&p2=$2&p3=$3&p4=$4&p5=$5 [l]
basically, takes 5 "friendly url folders" , assign value varibles , then, send index.php page
ie: http://www.example.com/ford/focus/grey/ $p1 = 'ford'; $p2 = 'focus'; $p3 = 'grey'; $p3 = 'grey';
so far, good.
now, need integrate 301 instruction (regexp?) in same .htaccess because initially, had parameters :
ie: http://www.example.com/ford/focus/grey/?lang=fr
i need rid of variables because google sees duplicate content (even if i'm using nofollow attribute on languages links)
ie: http://i.want.to.keep/my/url/?and_dump_get_variables http://www.example.com/ford/focus/grey/?lang=fr http://www.example.com/ford/focus/grey/?lang=en http://www.example.com/ford/focus/grey/?lang=sp ==> http://www.example.com/ford/focus/grey/
logically, instruction should interpreted between first , second block don't know start. hints?
thanks!
as understand want rid of query string , redirect (301 permanent redirect) same url without query string.
the rule below redirect every request has query string:
rewritecond %{query_string} !^$ rewritecond %{env:redirect_status} ^$ rewriterule ^(.*)$ http://%{http_host}/$1? [r=301,l]
1. ?
magic -- strip query string
2. desperately need line: rewritecond %{env:redirect_status} ^$
. problem may not work on apache setup , cannot give need make work (it works fine on vanilla apache v2.2.17 on windows).
after rewrite (internal redirect) occurred, goes next iteration , apache starts matching rules top again rewritten url. if not add above line, mod_rewrite apply above rule rewritten url form , end all urls rewritten /index.php
no parameters @ all.
if above not work, try code below:
# not existing files , folders rewritecond %{request_filename} -f [or] rewritecond %{request_filename} -d rewriterule .+ - [l] rewritecond %{query_string} !^$ rewriterule ^(.*)$ http://%{http_host}/$1? [r=301,l]
with of # not existing files , folders
rule, mod_rewrite stop rewriting after url rewritten /index.php?p1=...
format.
in case above not work @ (better -- in addition above -- suggest adding anyway) use <link rel="canonical" href="full_proper_rul"/>
in page:
Comments
Post a Comment