seo friendly multilanguage with remove trailing slash on php apache -
i've been trying rid of apache's rewrite issues when try both removing trailing slash , seo friendly multilanguage page @ same time.
to more clarify, able use functions of apache rewrite rules great codes below
# remove .php extension rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^([^\.]+)$ $1.php [nc,l] rewriterule ^(.*)/$ /$1 [l,r=301]
so achieve code ;
example.com/status.php
turns
example.com/status
that works great , code below assuming remove trailing slash every page ;
# remove trailing slash rewritecond %{request_filename} !-d rewritecond %{the_request} \s(.+?)/+[?\s] rewriterule ^(.+?)/$ /$1 [r=301,l]
so achieve code ;
example.com/status/
turns
example.com/status
all till however, when try use multilanguage abuses reason tries remove trailing slash ;
rewriterule ^([en|fr]{2})/(.*)$ $2?lang=$1&%{query_string} [l,qsa]
so need achieve ;
example.com/status?lang=fr
it should turn below 404 error;
example.com/fr/status
i've been seeking solution no luck
so need achieve ;
- remove .php extension
- remove trailing slash
- use status?lang=fr should turn /fr/status
- use status?lang=en should turn /status
thanks in advance
you can try :
rewriteengine on #remove trailing slashes rewritecond %{request_filename} !-d rewriterule ^(.*)/$ /$1 [r,l] # remove .php extension rewritecond %{request_filename} !-d rewritecond %{request_filename}\.php -f rewriterule ^([^\.]+)/?$ /$1.php [nc,l] #rewriting /status?lang=fr rewritecond %{the_request} /status\?lang=([^\s]+) rewriterule ^ /%1/status? [ne,r,l] rewriterule ^([^/]+)/status/?$ /status?lang=$1 [nc,l]
Comments
Post a Comment