Jump to content

(htaccess) remove trailing slash when + present in url


ozestretch

Recommended Posts

Currently I add trailing slash to all directories

 

so domain.com/666 redirs to domain.com/666/

 

I have a function that looks for '+'

domain.com/666+

or

domain.com/666+all

 

but I do not want these urls to add a trailing slash

 

So that works fine....

 

Issues is if a trailing slash is added (by user or whatever) at the end of a link like

domain.com/666+/

domain.com/666+all/

 

I want it removed.

 

 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]|/)$
RewriteCond %{REQUEST_URI} ([^+-+all])$
RewriteRule (.*)$ http://domain.com/$1/ [R=301,L]

 

I would post what I tried but I kept deleting and starting over.

Link to comment
Share on other sites

okay so this isn't what I needed either

 

RewriteCond %{REQUEST_URI} ([^+-+all])$

 

this is good as the only links with a + are desired to not have trailing slash

RewriteCond %{REQUEST_URI} ([^+])$

 

but the first method means if there is an a or an l it no work... help x 2 now lol

 

thanks

Link to comment
Share on other sites

thanks, unfortunately it doesn't offer what I need.

 

domain.com

domain.com/xxxxx to have trailing slash

 

domain.com/xxxxx+

and

domain.com/xxxxx+all to have no trailing slash

 

so far it works except the trailing slash is still added to

domain.com/xxxxx+all

 

 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]|/)$
RewriteCond %{REQUEST_URI} ([^+])$
RewriteRule (.*)$ http://domain.com/$1/ [QSA,R=301,L]
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1/ [QSA,L,R=301]

Link to comment
Share on other sites

Sorted - thnks corz

 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]|/)$
RewriteCond %{REQUEST_URI} ([^+])$
RewriteCond %{REQUEST_URI} !([a-zA-Z0-9]\+(all))$
RewriteRule (.*)$ http://domain.com$1/ [QSA,R=301,L]
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1/ [QSA,L,R=301]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.