apache2.4.7. htaccess rewrite Some details of the URL

Source: Internet
Author: User

Play the Apache rewrite rules tonight and discover some of the details that are easy to ignore and share.

First, describe the other related configurations of the instance environment:

Documentroot/var/www/html

The placement path of the. htaccess/var/www/html/l-production/public

1. Replace the "absolute" and "relative" rules, for example:

1 # Redirect Trailing slashes ... 2 rewriterule ^ (. *)/$/$1 [l,r=301]

This is an implementation that uses redirection to eliminate the last slash of the URL, where it is important to note the /$1 Slash, which is an "absolute" notation when I enter HTTP://127.0.0.1/in the browser l-production/public/js/, the URL is redirected to Http://127.0.0.1/js, and when I remove the /$1 slash, the URL is redirected to the expected HTTP// 127.0.0.1/l-production/public/js.

2. The pattern matching object is not related to rewritebase, but only with the directory where the. htaccess is located, for example:

1 rewritebase/l-Production23# Redirect Trailing slashes ... 4 rewriterule ^ (. *)/$ $1 [l,r=301]

In the browser input Http://127.0.0.1/L-Production/public/js/,url will be redirected to Http://127.0.0.1/L-Production/js, not HTTP://127.0.0.1/ L-production/public/js.

This shows that ^ (. *)/$ matches the string is js/, instead of the URL that removes the/l-production public/js,rewritebase only affects the substitution rule.

In addition, I also found in the final test that when you add a slash here, the redirect result is still http://127.0.0.1/L-Production/js, which means that after setting the rewritebase, all the substitution rules become "absolute".

apache2.4.7. htaccess rewrite Some details of the URL

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.