Under Windows, we generally use the Administrator account, so enabling these two items is very simple:
#LoadModule rewrite_module modules/mod_rewrite.so
in [Apache installation directory]/conf/httpd.conf and remove the preceding comment symbol #. If this line doesn't exist, add it. And confirm whether the file mod_rewrite.so
exists in the modules folder in the apache installation directory. This enables the Mod Rewrite
feature.[Apache安装目录]/conf/httpd.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
Change " AllowOverride None
" to " AllowOverride All
" so that all folders support .htaccess, or enable .htaccess for the specified folder, which can be added to [Apache安装目录]/conf/httpd.conf
<Directory "D:/sites/example/">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
This approach is generally configured together with the virtual host, so most of them will write the above configuration code into [Apache安装目录]/conf/extra/httpd-vhost.conf
, which is clearer and easier to manage.
After completing the appeal step, use link settings other than the default in WordPress's fixed link. WordPress will directly generate the corresponding .htaccess in its installation directory, so that the set link form can be used.
In Mac OS X, the root
account is generally not used, but root
related permissions are obtained through sudo
. Under normal circumstances, we place website files in a personal directory, such as ~/Sites
, which involves permission management on Mac OS, which is much more complicated than on Windows.
#LoadModule rewrite_module modules/mod_rewrite.so
, and remove the preceding comment symbol #.sudo vi /etc/apache2/extra/httpd-vhost.conf
and join <Directory "/Users/[用户名]/Sites">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
This way the entire ~/Sites
can support .htaccess
.
sudo vi /Private/etc/apache2/users/[用户名].conf
and change AllowOverride None
to AllowOverride All
. It should be noted that in previous Mac OS X versions, the path may be /private/etc/httpd/users/[用户名].conf
cd ~/Sites/Wordpress
touch .htaccess
chmod 777 .htaccess
The default permission of a new file is 644
, which can be seen through ls -l .htaccess
. At this time, the program cannot automatically write .htaccess. This situation is safer, but it needs to be written manually.
sudo apachectl restart
After completing the above settings, you can use WordPress’s fixed link function. It should be noted that if .htaccess is copied directly from Windows, an error of </IfModule> without matching <IfModule> section
may appear in the log. The simple solution is to create a new file and copy and paste again.
Original text: http://dancewithnet.com/2010/05/29/making-mod-rewrite-and-htaccess-work-on-mac-os-x/