Reply
Employee
owen
Posts: 213
Registered: 09-14-2011
0

Re: rewrite.script how to remove trailing slashes

There are many ways to remove trailing slashes, you could use a regular expression match similar to your rewrite rule, but I would probably avoid that and do something like this instead:

 

   1. #Read in the path
   2. $path = http.getPath();
   3. # if it's the root dir exit the script
   4. if( $path =="/")
   5.   break;
   6. # if we end with a slash redirect, this does a 302 redirect
   7. if(string.endswith($path,"/"))
   8.    http.redirect(string.drop($path,1));

 

This script uses http.redirect() which issues a 302 redirect, if you want it to be a 301, then you could switch the last block with the one below. The version below uses the more long winded http.sendResponse(), but this function allows you to send back any HTTP resopnse you wish, not only redirects.

 

   1. # Issue a 301 permanent redirect
   2. if(string.endswith($path,"/")){
   3.    $location =string.drop($path,1);
   4.    http.sendResponse("301 Moved","text/plain","Object moved to: ". $location,"Location: ". $location);
   5. }

 

Administrator
mgyles
Posts: 26
Registered: 10-20-2011
0

rewrite.script how to remove trailing slashes

Asked by Community member: cusackd on Tue, 27/09/2011 - 20:26

 

This was my mod_rewrite script

 

RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

 

I now need to change this so it works with zeus it seems to be the only thing holding me back from going live.

‬‪‬‪‬‪