2

I have the following URLs:

example.com/test/ example.com/test/mode/ 

that needs to be automatically converted to:

example.com/test example.com/test/mode 

Basically, I want the trailing slash to be removed.

My existing .htaccess

RewriteEngine On # Rule to handle example.com/xyz/mode RewriteRule ^(\w+)/(\w+)/?$ /index.php?id=$1&mode=$2 [L,QSA] # Rule to handle example.com/xyz RewriteRule ^(\w+)/?$ /index.php?id=$1 [L,QSA] 

1 Answer 1

1

Add this rule on top to remove trailing slash:

RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s] RewriteRule ^ %1 [R=302,L] 
Sign up to request clarification or add additional context in comments.

1 Comment

This is working. Thank you! You seem to be very good in .htaccess redirects :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.