Apache URL redirect avoids URL end slash problem

Source: Internet
Author: User

Describe:

Each net owner has been tortured by a trailing slash problem, and if there is no trailing slash in the URL, the server will assume that the URL is invalid and return an error because the server will look for the file Foo based on/~quux/foo instead of displaying the directory. In fact, many times, this problem should be left to the user to add "/" to solve, but users will directly enter the Web site. This will result in a 301 redirect request. And then again looking into the/index.html.

Method:

The most intuitive way is to make Apache automatically plus "/", the use of external redirection to the browser can correctly find the file, if we only do internal redirection, you can only display the table of Contents page, in this directory page image file will be due to the relative URL of the problem can not find. For example, when we request a/~quux/foo/index.html image.gif, redirects become/~quux/image.gif.

So we should use the following methods:

Rewriteengine on

Rewritebase/~quux/

Rewriterule ^foo$ foo/[R]

This method also applies to. htaccess files are set within each directory, but this setting overrides the original primary configuration file.

Rewriteengine on

Rewritebase/~quux/

Rewritecond%{request_filename}-D

Rewriterule ^ (. +[^/]) ___fckpd___17nbsp; $1/[R]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.