1

I am using using htaccess for routing variables with slashes making a pretty url.

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L] 

However I cant seem to prevent a trailing slash at the very end so the url ends without a /. Can anyone help me add this rule to the existing condition please.

1 Answer 1

1

You can have your .htaccess as this:

Options -MultiViews
RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /myproject/table1/table2/$1 [NE,R=301,L]

# front router rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
Sign up to request clarification or add additional context in comments.

6 Comments

thank you but this clears out the sub directory the project is in. this is my current local url localhost/myproject/table1/table2/sub-folder/detail/ and it truncates it to http://localhost/sub-folder/detail
when i deploy this live getting an error The server encountered an internal error or misconfiguration and was unable to complete your request. Do you know what could be causing this?
error: .htaccess: RewriteRule: invalid HTTP response code '308' for flag 'R'
Ah ok then use R=301 instead of R=308 as that is supported in only newer Apache versions.
WOW, YOURE THE BEST!!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.