简体   繁体   中英

.htaccess prevent default folder 301 redirects

I have a very small site with my .htaccess set up to allow urls like:

mysite.com/brand/login
mysite.com/brand/dashboard
mysite.com/controller

These all redirect to:

mysite.com/driver.php?___=brand/login
mysite.com/driver.php?___=brand/dashboard
mysite.com/driver.php?___=controller

I'm simply using one rewrite rule for this:

RewriteRule ^(([a-zA-Z0-9\-\_]+/?)*)$ index.php?___=$1 [L,QSA]

But anyway, it works great, until I have a page with the same name as a folder in my site.

// I navigate to:
mysite.com/javascript

// The site automatically provides a 301 redirect to
mysite.com/javascript/? ___=javascript

And now that ugly URL is showing up in my users' browsers. Is there any way to tell the site that I want to take care of all redirects myself?

EDIT: I determined this using fiddler. Another example:

在此处输入图片说明

Welp found the answer right after posting this. This line in .htaccess fixed the problem.

DirectorySlash Off

I then, of course, had to clear my browser cache to make it forget about the 301.

https://httpd.apache.org/docs/2.4/mod/mod_dir.html#directoryslash

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

Typically if a user requests a resource without a trailing slash, which points to a directory, mod_dir redirects him to the same resource, but with trailing slash

And a security warning:

Turning off the trailing slash redirect may result in an information disclosure. Consider a situation where mod_autoindex is active (Options +Indexes) and DirectoryIndex is set to a valid resource (say, index.html) and there's no other special handler defined for that URL. In this case a request with a trailing slash would show the index.html file. But a request without trailing slash would list the directory contents.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM