Question

I've a htaccess file that looks like this

Options +FollowSymLinks
Options -Indexes
RewriteEngine on
RewriteBase /website/

# add slashes after link/folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://localhost/website/$1/ [L,R=301]

# shorten URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&beta=$2&gamma=$3&delta=$4 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&beta=$2&gamma=$3 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&beta=$2 [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]

It all works fine, until it has to add a slash to a link that has a matching folder on the root directory.

Example: If I write down www.example.com/live and there is no folder named "live" in www.example.com/, the script is going to add a slash. However, since there is a folder named "live", the script is once again going to add the slash, but it will also add this ?page=live so the URL will look like this www.example.com/live/?page=live

My question is why ?page=something&beta=something&gamma=...etc. is added to the back and how should I make it stop?

Was it helpful?

Solution

DirectorySlash Off

should fix that.

edit: to do what DirectorySlash normally does use:

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ /$1/ [L,R=301]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top