Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess trailing slash issue

I am getting some problem for without trailing slash url. I searched in Google, but not able to get the exact result.

  From Url : local.xxxx.com/stories

When I am trying with the above Url, It redirects to

  To Url : local.xxxx.com/sapp/View//stories/

Htaccess:

DirectorySlash Off
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -d
RewriteRule ^ /app/View/%{REQUEST_URI} [L]

Now I am getting 403 Forbidden error. You don't have permission to access /app/View//storieson this server.

If I will add trailing slash, then its working perfectly. If there is no slash, we can add slash at the end of the url if there are no params.

Can any body suggest how can I achieve this.

like image 454
robert Avatar asked May 01 '26 12:05

robert


1 Answers

It is most likely due to the fact that /app/View/stories/ is a real directory and Apache's mod_dir is adding a trailing slash.

You can fix using this code:

DirectorySlash Off
RewriteEngine On

# internally add a trailing slash to directories
RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -d
RewriteRule [^/]$ /app/View/%{REQUEST_URI}/ [L] 

RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/app/View/%{REQUEST_URI} -d
RewriteRule ^ /app/View/%{REQUEST_URI} [L]
like image 142
anubhava Avatar answered May 03 '26 01:05

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!