Enable mod rewrite and. htaccess

Source: Internet
Author: User
Tags join manual writing regular expression

The Apache mode rewrite module provides a rewrite engine based on the regular expression parser to rewrite URL requests in real time. In most cases, it is used in conjunction with the. htaccess file. For example, the URL of this article (http://dancewithnet.com/2010/05/29/making-mod-rewrite-and-htaccess-work-on-mac-os-x) is WordPress with MoD The rewrite module is implemented with the. htaccess file, known as a fixed link (permalinks).

Windows

Under Windows, we typically use the administrator account, so enabling these two is simple:

In the Apache installation directory]/conf/httpd.conf find #loadmodule rewrite_module modules/mod_rewrite.so, remove the previous annotation symbol #. If this line is not in use, add it. Verify that the mod_rewrite.so file is in the Modules folder under the Apache installation directory. This enables the MoD rewrite feature.

Found in the Apache installation directory]/conf/httpd.conf

The following are the referenced contents:

<directory/>
Options FollowSymLinks
AllowOverride None
Order Deny,allow
Deny from all
</Directory>

Change "allowoverride None" to "allowoverride all" so that all folders are supported. htaccess, or enabled for the specified folder. htaccess, can be installed in the Apache directory]/conf/ Join in httpd.conf

The following are the referenced contents:

<directory "d:/sites/example/" >
Options Indexes FollowSymLinks
AllowOverride All
Order Allow,deny
Allow from all
</Directory>

This approach is typically configured with a virtual host, so most of the configuration code will be written to the [Apache installation directory]/conf/extra/httpd-vhost.conf, which is much clearer and easier to manage.

After you restart Apache, it's OK.

After completing the appeal procedure, WordPress will use the link settings in the permalink in WordPress, in addition to the default settings, and the htaccess can be generated directly in its installation directory.

Mac OS X

Instead of using the root account in Mac OS X, you get root-related permissions through sudo. In general, we put the Web site files in a personal directory, such as ~/sites, so that the rights of Mac OS management, compared to Windows, a lot more complicated.

Run sudo vi/etc/apache2/httpd.conf at the terminal, find the #loadmodule rewrite_module modules/mod_rewrite.so, and remove the previous annotation symbol #.

Run sudo vi/etc/apache2/extra/httpd-vhost.conf, join

The following are the referenced contents:

<directory "/users/[username]/sites" >
Options Indexes followsymlinks MultiViews
AllowOverride All
Order Allow,deny
Allow from all
</Directory>

So the whole ~/sites can support. htaccess.

Run sudo vi/private/etc/apache2/users/[username].conf, change the allowoverride none to allowoverride all. It should be noted that the previous version of Mac OS X, the path might be/private/etc/httpd/users/[username].conf

In the directory you want to create a new. htaccess, and modify its permissions to 777, here is still the use of WordPress fixed link as an example.

The following are the referenced contents:

CD ~/sites/wordpress
Touch. htaccess
chmod 777. htaccess

The default permissions for new files are 644, which can be seen by Ls-l. htaccess, which is not automatically written to. htaccess, which is safe, but requires manual writing.

Restart Apache:sudo apachectl after exiting restart

Once you have finished this setup, you can use the fixed link feature of WordPress. It should be noted that if. htaccess is copied directly from Windows, the log may appear "/ifmodule" without matching "ifmodule" section of the error. The simple solution is to create a new file and copy the paste again.

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.