apache - .htaccess rewrite issue with no slash -
apache - .htaccess rewrite issue with no slash -
i've searched awhile , can't find solution issue, maybe i'm not searching right thing, anyways, here's what's happening.
i have next mod_rewrites in .htaccess file. rewrites work perfectly, if not have trailing slash, show's variable automatically in url. please see illustration below clear understanding.
url sampleif come in http://website.com/test/
, (notice trailing slash) page url remain exact same , load content perfectly!
but, if forget trailing slash, ie: http://website.com/test
, page url alter http://website.com/test/?var1=test
. (now notice had left out trailing slash begin with) content still loads , works fine, url "ugly" now.
i hope made clear, if have questions, please sense free ask. give thanks you!
.htaccess code options +followsymlinks rewriteengine on rewritecond %{https} off rewriterule (.*) https://%{http_host}%{request_uri} [r,l] rewriterule ^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/?$ _client.php?var1=$1&var2=$2&var3=$3&var4=$4&var5=$5 [l] rewriterule ^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/?$ _client.php?var1=$1&var2=$2&var3=$3&var4=$4 [l] rewriterule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ _client.php?var1=$1&var2=$2&var3=$3 [l] rewriterule ^([\w-]+)/([\w-]+)/?$ _client.php?var1=$1&var2=$2 [l] rewriterule ^([\w-]+)/?$ _client.php?var1=$1 [l]
this happening due mod_dir
module adds trailing slash after mod_rewrite
rules have finished. have rules avoid problem:
directoryslash off options +followsymlinks rewriteengine on rewritecond %{https} off rewriterule (.*) https://%{http_host}%{request_uri} [r=302,l] # add together trailing slash directories rewritecond %{document_root}/$1 -d rewriterule ^(.*?[^/])$ %{request_uri}/ [l,r=302] rewriterule ^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/?$ _client.php?var1=$1&var2=$2&var3=$3&var4=$4&var5=$5 [l,qsa] rewriterule ^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/?$ _client.php?var1=$1&var2=$2&var3=$3&var4=$4 [l,qsa] rewriterule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ _client.php?var1=$1&var2=$2&var3=$3 [l,qsa] rewriterule ^([\w-]+)/([\w-]+)/?$ _client.php?var1=$1&var2=$2 [l,qsa] rewriterule ^([\w-]+)/?$ _client.php?var1=$1 [l,qsa]
apache .htaccess mod-rewrite redirect url-rewriting
Comments
Post a Comment