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.

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

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]

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.