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
#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.
- In
[Apache安装目录]/conf/httpd.conf
Found 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.
- 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.
- Run sudo vi/etc/apache2/httpd.conf at the terminal, find
#LoadModule rewrite_module modules/mod_rewrite.so
, and remove the previous annotation symbol #.
- 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
.
- 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
- 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.
- 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/