问题:我无法使用Wordpress创建友好永久链接。
我们正在运行Apache。我试图修改.htaccess,但没有成功。
以下是我的.htaccess文件的原始内容:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
我找到了一个有类似问题的人,但对他而言,/blog
位于一个嵌套的子目录中。见this post
这是他的解决方案:
<VirtualHost *:80>
DocumentRoot /home/user/
ServerName mydomain.com
ServerAlias www.mydomain.com
<Directory "/home/user">
Options FollowSymLinks
AllowOverride none
Order allow,deny
Allow from all
</Directory>
<Directory "/home/user/blog">
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
我认为我的答案在他的解决方案中,但我无法弄清楚如何根据我的具体情况修改此代码段。我的Wordpress位于domain.com/blog
目录中。
答案 0 :(得分:0)
您必须向主持人说,允许其他文件(例如.htaccess
)覆盖规则。
虚拟主机
<VirtualHost *:80>
DocumentRoot /home/user/
ServerName mydomain.com
ServerAlias www.mydomain.com
<Directory "/home/user">
Options FollowSymLinks
AllowOverride none
Order allow,deny
Allow from all
</Directory>
<Directory "/home/user/blog">
Options FollowSymLinks
## ADD THESE!
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
否则,您可以删除完整的博客指令(<Directory "/home/user/blog">
),并将AllowOverride none
设置为AllowOverride All
:
<VirtualHost *:80>
DocumentRoot /home/user/
ServerName mydomain.com
ServerAlias www.mydomain.com
<Directory "/home/user">
Options FollowSymLinks
# Change this!
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
您可以在.htaccess
(/home/user/blog/.htaccess
)上重写:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
这是我网站上的一个小例子:
<VirtualHost *:80>
ServerAdmin support@adi-code.de
ServerName adi-code.de
ServerAlias adi-code.de www.adi-code.de *.adi-code.de
DocumentRoot /opt/adi
<Directory /opt/adi/>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/adicode_error.log
LogLevel warn
CustomLog /var/log/apache2/adicode_access.log combined
</VirtualHost>