Apache mode rewrite module with. htaccess file

Source: Internet
Author: User
Tags 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:

  1. In the Apache installation directory]/conf/httpd.conf #LoadModule rewrite_module modules/mod_rewrite.so , remove the previous annotation symbol #. If this line is not in use, add it. Verify that the file is in the Modules folder under the Apache installation directory mod_rewrite.so . This enables the Mod Rewrite functionality.
  2. In[Apache安装目录]/conf/httpd.confFound in
    <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 [Apache安装目录]/conf/httpd.conf added in

    <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 is written to the above, which is [Apache安装目录]/conf/extra/httpd-vhost.conf more clear and manageable.

  3. 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

In Mac OS x, you don't typically use an root account, but you sudo get root permissions. In general, we put the Web site files in a personal directory, for example ~/Sites , this involves Mac OS Rights management, compared to Windows, a lot more complicated.

  1. Run sudo vi/etc/apache2/httpd.conf at the terminal, find #LoadModule rewrite_module modules/mod_rewrite.so , and remove the previous annotation symbol #.
  2. Run sudo vi /etc/apache2/extra/httpd-vhost.conf , join
    <Directory "/Users/[用户名]/Sites">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    So the whole ~/Sites thing can be supported .htaccess .

  3. Run sudo vi /Private/etc/apache2/users/[用户名].conf , and change it AllowOverride None into AllowOverride All . It should be noted that the previous version of Mac OS X, the path may be /private/etc/httpd/users/[用户名].conf
  4. 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.
    cd ~/Sites/Wordpress
    touch .htaccess
    chmod 777 .htaccess

    The permissions for the new file are by default 644 , as ls -l .htaccess you can see that the program is not automatically written to. htaccess, which is more secure, but requires manual writing.

  5. Restart Apache after exiting: sudo apachectl 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 error may appear in the log. </IfModule> without matching <IfModule> section The simple solution is to create a new file and copy the paste again.

Original: http://dancewithnet.com/2010/05/29/making-mod-rewrite-and-htaccess-work-on-mac-os-x/



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.