Ubuntu14.14 How to open Apache rewrite function

Source: Internet
Author: User

How to turn on the Apache rewrite function on Ubuntu
Release time: 2012-09-11 Editor: Scripting Academy
This paper introduces the method of Urlrewrite function of Apache in UBUNTN system.


Opening Apache Urlrewrite on Windows is very simple, because Apache User Configuration is placed in the http.conf file, to turn on the rewrite function, only need to put the file LoadModule rewrite_module Modules/mod_rewrite.so the front of the eye, then restart Apache.

On Ubuntu, however, the default Apache package configuration is stored according to directories and files, and the/etc/apache2 directory contains CONF.D, mods-available, mods-enabled, Sites-available, Sites-enabled folder, apache2.conf, Envvars, httpd.conf (user profile), magic, ports.conf (Apache port configuration) profile.

First, Ubuntu default does not turn on rewrite support

Where mods-available refers to the available modules, mods-enabled refers to the modules that are currently loaded by default. httpd.conf default is an empty file, because most of the load work is scattered into different configuration files, the overall load profile is apache2.conf, and some of the contents are as follows:

# Include Module configuration:include/etc/apache2/mods-enabled/*.loadinclude/etc/apache2/mods-enabled/*.conf# Include all the user configurations:include/etc/apache2/httpd.conf# Include ports listinginclude/etc/apache2/ ports.conf......# include generic snippets of statementsinclude/etc/apache2/conf.d/# include the virtual host Configurat ions:include/etc/apache2/sites-enabled/

  


As you can see from these statements, loading has been dispersed across different configuration files, which seems to be more reasonable and manageable. below to see how to open the rewrite module, when the user needs to use the 301 redirect, pseudo-static and other rewrite functions, generally used to use the. htaccess file configuration, such as the following 301 redirects:

Options +followsymlinksrewriteengine Onrewritecond%{http_host} ^abc.com [Nc]rewriterule ^ (. *) $ http://www.shouce.ren /$1 [L,r=301]rewritecond%{http_host} ^www.abc.com[nc]rewriterule ^ (. *) $ http://www.shouce.ren/$1 [L,R=301]

  



After the configuration is complete, use the/etc/init.d/apache2 reload command load to take effect, if the rewrite function is not turned on, then a 500 error (browser display), view log error is as follows:
[Sun Jan 30 02:41:29 2011] [Alert] [Client 12.34.56.78]/srv/www/shouce.ren/public_html/.htaccess:invalid command ' Rewriteengine ', perhaps misspelled or Defined by a module not included in the server configuration
Instructions need to manually turn on the rewrite module loading, the load opening process is as follows.

Second, manually open the load rewrite

1. Use terminal tools to connect to the server, enter the Administrator account number and password

2. Execute Load Rewrite module:
A2enmod rewrite
After execution, you will be prompted to OK and restart the Apache command (/etc/init.d/apache2 restart).

3, refer to the above directory configuration, do a start link (the next time to start the automatic loading):

Ln-s/etc/apache2/mods-available/rewrite.load/etc/apache2/mods-enabled/rewrite.load

  

After execution, a shortcut is created in the Mods-available directory to connect to the rewrite module under mods-enabled.

4. Restart Apache:


/etc/init.d/apache2 restart
Third, single default site configuration and redirection reference

If you have only one Web site and default to the default WWW folder assigned by Apache (without creating a separate profile, such as/sites-availbe/shouce.ren), you may need to modify the/etc/apache2/ Sites-available/default This file, allowoverride none of them is modified to allowoverride all, Because the default configuration also shuts down. htaccess overload, open after. htaccess will not take effect.

<virtualhost 12.34.56.78:80>serveradmin [Email protected]documentroot/var/www<directory/>Options Followsymlinksallowoverride none</directory><directory/var/www/>options Indexes FollowSymLinks Multiviewsallowoverride Noneorder Allow,denyallow from all</directory>scriptalias/cgi-bin//usr/lib/cgi-bin/ <directory "/usr/lib/cgi-bin" >allowoverride noneoptions +execcgi-multiviews +SymLinksIfOwnerMatchOrder Allow, Denyallow from all</directory>errorlog/var/log/apache2/error.log# Possible values Include:debug, info, notice, Warn, error, crit,# alert, Emerg. LogLevel warncustomlog/var/log/apache2/access.log combinedalias/doc/"/usr/share/doc/" <directory "/usr/share/ doc/">options Indexes multiviews followsymlinksallowoverride noneorder deny,allowdeny from AllAllow from 127.0.0.0/ 255.0.0.0::1/128</directory></virtualhost>

  

After the configuration is complete, restart Apache, command:/etc/init.d/apache2 restart

Ubuntu14.14 How to open Apache rewrite function

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.