Ubuntu14.14 detailed instructions on how to enable Apache Rewrite

Source: Internet
Author: User

Ubuntu14.14 detailed instructions on how to enable Apache Rewrite
How to enable the Apache Rewrite function on Ubuntu this article introduces how to enable the urlrewrite function of apache in the ipvtn system. Enabling Apache urlRewrite on Windows is very simple, because apache user configuration is stored in http. in the conf file, to enable the Rewrite function, you only need to remove the check in front of LoadModule rewrite_module modules/mod_rewrite.so in the file, and then restart APACHE. However, it is different on Ubuntu. The default Apache package configuration is stored by directory and file, and the/etc/apache2 directory contains conf. d. sdks-available, sdks-enabled, sites-available, and sites-enabled folders, apache2.conf, envvars, and httpd. conf (user configuration file), magic, ports. conf (APACHE port configuration) configuration file. 1. Rewrite support is not enabled for Ubuntu by default, where "mod-available" refers to available modules, and "mod-enabled" refers to the modules already loaded by default. Httpd. conf is an empty file by default, because most of the loading work is distributed to different configuration files, and the overall loading configuration file is apache2.conf. Part of the content is 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 configurations:Include /etc/apache2/sites-enabled/

 

From these statements, we can see that the loading work has been distributed to different configuration files, which seems more reasonable and convenient to manage. Next, let's take a look at how to enable the Rewrite module. When users need to use Rewrite functions such as 301 redirection and pseudo-static, they are generally used to using the. htaccess file configuration, such as the following 301 redirection:
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]

 

Use/etc/init. d/apache2 reload command loading takes effect. If the Rewrite function is not enabled, Error 500 will occur (displayed in the browser). The following is a LOG check error: [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 supported in the server configuration indicates that you need to manually enable the Rewrite module loading. the loading process is as follows. 2. manually enable Rewrite loading. 1. Use a terminal tool to connect to the server. Enter the Administrator account and password. 2. Execute the Rewrite module: a2enmod rewrite, the prompt "OK" and "restart Apache command (/etc/init. d/apache2 restart ). 3. Follow the preceding directory configuration to create a startup Link (automatically loaded upon next startup): ln-s/etc/apache2/mod-available/rewrite. load/etc/apache2/mod-enabled/rewrite. after the load command is executed, a shortcut is created in the directory of "mod-available" to connect to the rewrite module under "mod-enabled. 4. Restart apache:/etc/init. d/apache2 restart 3. Single default website configuration and redirection reference if there is only one website and the default www folder allocated by apache is used by default (no separate configuration file is created, for example,/sites-availbe/shouce. ren), you may also need to modify the/etc/apache2/sites-available/default file and change AllowOverride None to AllowOverride All because it is disabled by default in the default configuration. htaccess overload. htaccess takes effect.
<VirtualHost 12.34.56.78:80>ServerAdmin webmaster@localhostDocumentRoot /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 with the command:/etc/init. d/apache2 restart.

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.