apache - Url renaming using .htaccess file -
most redirections , removing file extensions or dynamic urls.
the problem being can't simple static url rename
options +followsymlinks rewriteengine on rewriterule ^filethathasalongname file.html what have 'mysite.co.uk/filethathasalongname.html'
what want 'mysite.co.uk/file/' while file = file.html
using:
options +followsymlinks -multiviews rewriteengine on rewriterule ^fileiwanttochange.html friendlynamed.html using gives me error multiple choices
+++++++++++++++++edit+++++++++++++++++++++++++
thought i'd add final version people at, may help, anwser below correct.
options +followsymlinks -multiviews directoryslash off rewriteengine on rewritecond %{script_filename}/ -d rewritecond %{script_filename}.html !-f rewriterule [^/]$ %{request_uri}/ [r=301,l] rewritecond %{env:redirect_status} ^$ rewriterule ^(.+)\.html$ /$1 [r=301,l] rewriterule ^friendlynamed.html fileiwanttochange.html [l] rewritecond %{script_filename}.html -f rewriterule [^/]$ %{request_uri}.html [qsa,l] rewritecond %{http_host} ^www.mysire.co.uk [nc] rewriterule ^(.*)$ http://mysite.co.uk/$1 [l,r=301] all works charm!
i see multiple issues going on. firstly regular expression matched against friendly url user types in. need swap friendly url , file path each other. friendly or "fake" name goes on left while url redirect silently goes on right. make sure you've set directory base /. it's add [l] enforce last rule in case in same file tries rewrite path. due note other htaccess files lower down, depending on files location, checked when enforcing rule has last rule. junk options part completely. give try:
rewritebase / rewriteengine on rewriterule ^friendlynamed.html fileiwanttochange.html [l]
Comments
Post a Comment