Remove/Unforce Trailing Slash

ISAPI_Rewrite is a powerful URL manipulation engine based on regular expressions
User avatar
Posts: 5
Joined: 01 Apr 2013, 21:27
Location: Minnesota, USA

Remove/Unforce Trailing Slash

19 Mar 2014, 22:25

Hi. Currently I'm forcing a trailing slash on a website.

Current rule:
# Force Trailing Slash
RewriteCond Host: (.*)
RewriteRule ([^.?]+[^.?/]) http\://$1$2/ [I,R]

I'd like to start removing the trailing slash from websites. So instead of http://www.3plains.com/logos/ I'd like to have http://www.3plains.com/logos

Any help or the correct rule would be appreciated. Thanks,

Ryan

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Remove/Unforce Trailing Slash

20 Mar 2014, 06:52

Hello,

Please try to use the following rule:

[ISAPI_Rewrite]
RewriteRule (.*)/ http\://$1 [RP]

User avatar
Posts: 5
Joined: 01 Apr 2013, 21:27
Location: Minnesota, USA

Re: Remove/Unforce Trailing Slash

29 Mar 2014, 03:55

Anton,

I tried a few things and did get it to work with my application. Is this following code correct or is there a better way to write it?

[ISAPI_Rewrite]
# Force www
RewriteCond Host: ^mywebsite\.com
RewriteRule (.*) http\://www\.mywebsite\.com$1 [I,RP]

# Force Trailing Slash
RewriteCond Host: (.*)
RewriteRule ([^.?]+[^.?/])/ http\://$1$2 [I,RP]

# Pages
RewriteRule /([^.?]+[^.?/]) /code/content.php\?id=$1 [I,L]

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Remove/Unforce Trailing Slash

31 Mar 2014, 04:42

Your code looks absolutely fine. Stick to it.

Return to ISAPI_Rewrite 2.x

Who is online

Users browsing this forum: No registered users and 13 guests