.htaccess - mod_rewrite changing real URLs -
rewriteengine on rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^([^/]*)$ /?a=$1 [l] rewriterule ^([^/]*)/([^/]*)$ /?a=$1&app=$2 [l] rewritecond %{http_host} ^www\.(.*)$ [nc] rewriterule ^(.*)$ http://%1/$1 [r=301,l]
this suppose make urls search engine , user friendly, problem if goes http://pattersoncode.ca/realurlhere/ redirects them error page though it's real directory. there anyway stop this? must thinking trying go http://pattersoncode.ca?a=realurlhere.
it happening because of incorrect regular expression in line:
rewriterule ^([^/]*)$ /?a=$1 [l]
which matching 0 or more characters until /
found. change to:
rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^([^/]*)/?$ /?a=$1 [l]
and problem fixed. in answer have made trailing slash options both /realurlhere/
, /realurlhere
supported.
Comments
Post a Comment