apache - mod_rewrite: remove trailing slash for specific files only -


i trying remove trailing slash urls ending file extension only, .txt.

here full .htaccess file:

rewriteengine on rewritebase /  rewritecond %{the_request} (.*)\.txt.html rewriterule ^(.)\.txt.html /$1.txt [r=301,l]  rewritecond %{the_request} (.)\.txt rewriterule ^(.)\.txt $1.txt.html [l]  rewritecond %{the_request} (.)\.txt/ rewriterule ^(.*)\.txt\/ $1.txt [r=301] 

everything fine except rule for .txt/ adds full path url. possible make work relative paths?

for example, url

http://test.local:8080/doc/cons/bo/dwnlds/test.txt/

goes this

http://test.local:8080/users/dev1/documents/96/test.org/doc/cons/bo/dwnlds/test.txt.

how fix issue?

you need add leading slash target (.*) not contain it, hence weird file system path result:

rewriterule ^(.*)\.txt\/ /$1.txt [r=301] 

it happens because rewriterules defaults filesystem path if exists (in case, it's hard tell if target url-path or filesystem path because there's no base folder). see documentation on these @ http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -