Web server Apache URL rewrite

Source: Internet
Author: User

First, URL rewrite function

Implementing Pseudo-static

Picture anti-theft chain

Customizing the 404 error page


Second, rewrite the module to open

Apache configuration file in the httpd.conf file opens:

LoadModule Rewrite_module modules/mod_rewrite.so

Where do you configure rewrite rules? What is the difference in scope ?

1) can be used in the Apache Master profile httpd.conf (server level, for servers with administrative privileges)

2) can be used in the virtual host configuration defined in the httpd.conf

3) can be used in configuration file . htaccess (directory level, for virtual hosts without administrative privileges)

If you do not have administrator rights on the server where your site content resides, or if your site is placed on the ISP's server
On hosting and so on, you can't overwrite the master profile, but you can make the directory where your Web site content resides
With Write permissions, you can set your own. htaccess file to achieve the same purpose.
But you need to be sure.The following is defined in the main configuration file for the directory in which your site resides:
Options Indexes FollowSymLinks
AllowOverride All
Otherwise, your. htaccess won't work.


Iv. Examples of rewriting

1) Hide a directory under Apache so that any requests for that directory are redirected to another file.

A) how to implement httpd.conf

We put down the part of the face to/usr/local/apache/conf/httpd.conf:
Options Indexes FollowSymLinks
AllowOverride All
Rewriteengine on
Rewritebase/
Rewriterule ^ (. *) $ index.html.en [r=301]


Note: Rewriteengine on is a rewrite engine switch, and if set to off, any rewrite rule definitions will not be
The other advantage of this switch is that if you want to remove the rewrite rules temporarily, then turn off and then restart Apache.
You do not have to comment out the rewrite rules for the following strips.
The Rewritebase/function is if the section is rewritten in the following Rewriterule definition (file
Name Index.html.en) in front of no/, is relative to the directory, relative to this rewritebase after the definition is also
is/usr/local/apache/htdocs/index.html.en, otherwise, if there is no rewritebase/this
One, it is rewritten into http://192.168.1.56/usr/local/apache/htdocs/manual/index.html.en,
is obviously not correct.


But here we can also not rewritebase/, but instead:
Rewriteengine on
Rewriterule ^ (. *) $/index.html.en [r=301]
Or
Rewriteengine on
Rewriterule ^ (. *) $ http://192.168.1.56/index.html.en [r=301]


b>. How to implement Htaccess


Let's put the following part to httpd.conf:
Options Indexes FollowSymLinks
AllowOverride All


and put the following part into the/usr/local/apache/htdocs/manual/.htaccess.
Rewriteengine on
Rewritebase/
Rewriterule ^ (. *) $ index.html.en [r=301]


Note: Any changes made to the file. htaccess do not require a restart of Apache.


Web server Apache URL rewrite

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.