Apache URL Redirection Avoids URL Ending Slash Issues

  
                  End slash problem Description: Each netizen has been plagued by a trailing slash problem. If there is no trailing slash in the URL, the server will consider the URL invalid and return an error because the server will look for it according to /~quux/foo Foo this file instead of displaying this directory. In fact, many times, this problem should be left to the user to add "/" to solve, but the user will directly enter the URL. This will result in a 301 redirect request. Then look again to /index.html. Method: The most intuitive way is to make Apache automatically add "/". Use external redirect to make the browser find the file correctly. If we only do internal redirection, we can only display the directory page correctly. The image in this directory page. The file will not be found due to a problem with the relative URL. For example, when we request image.gif of /~quux/foo/index.html, the redirect will become /~quux/image.gif. So we should use the following method:


RewriteEngine on 
RewriteBase /~quux/
RewriteRule ^foo$ foo/[R] 


This method also works. The htaccess file is set in each directory, but this setting overrides the original main configuration file.


RewriteEngine on 
RewriteBase /~quux/
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^(.+[^/])___FCKpd___17nbsp; $1/[R]
Copyright © Windows knowledge All Rights Reserved