Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Who adds a slash at the end of my url?

I'm using mod_rewrite to rewrite /products to /products.php. I've got this code in /.htaccess

Options FollowSymLinks
RewriteEngine on

RewriteRule ^([a-zA-z]+)$ /$1.php [PT,L]

Unfortunately there is also a folder /products/ on my server.

My problem is, when I try to access http://mydomain.com/products my request is redirected to http://mydomain.com/products/ and showing me an error because I don't have an index for that directory.

Who is redirecting me? Apache, my UserAgent? How do I prevent that this happens without changing the folder name or the rewrite rule?

like image 236
sauerburger Avatar asked Feb 25 '23 06:02

sauerburger


1 Answers

You need to look up the "DirectorySlash Directive".

The DirectorySlash directive determines whether mod_dir should fixup URLs pointing to a directory or not.

http://httpd.apache.org/docs/2.2/mod/mod_dir.html

You could also try adding an optional slash to you rewrite rule:

RewriteRule ^([a-zA-z]+)/?$ /$1.php [PT,L]

Trailing slashes problem

like image 179
zaf Avatar answered Mar 04 '23 09:03

zaf