Who adds a slash at the end of my URL?

I am using mod_rewrite to overwrite / products in /products.php . I have this code in /. Htaccess

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

Unfortunately, my server also has a / products / folder.

My problem is that 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 do not have an index for this directory .

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

+4
source share
3 answers

You need to find the "DirectorySlash Directive".

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

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

You can also try adding an extra slash to the rewrite rule:

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

Slash issue

+5
source

Each browser adds a trailing slash after your request, unless it is “.something” because it considers it to be a folder. To avoid this, your rewrite rule should look like this:

RewriteRule / products (. *) $ / Index.php? Page = products

OR

RewriteRule / products / index.php? Page = products

Thus, it will rewrite each request with "/ products" in it with or without a trailing slash.

The only thing is that your folder / products / will not be available on request http. If you want this, you must change the folder name or page name.

+2
source

You may have activated MultiViews on your Apache.

+1
source

All Articles