[英]How to configure permalinks (.htaccess) for Wordpress in subdirectory
The problem: I can't create friendly permalinks using Wordpress. 问题:我无法使用Wordpress创建友好的永久链接。
We are running Apache. 我们正在运行Apache。 I am attempting to modify .htaccess, but with no success.
我正在尝试修改.htaccess,但没有成功。
Here is the original content of my .htaccess file: 这是我的.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>
I found a guy with a similar problem, but for him the /blog
was in a nested subdirectory. 我发现了一个有类似问题的人,但对他来说,
/blog
位于嵌套子目录中。 See this post 看到这个帖子
Here is his solution: 这是他的解决方案:
<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>
I think my answer is in his solution, but I can't figure out how to modify this snippet for my particular case. 我认为我的答案在他的解决方案中,但是我不知道如何针对我的特定情况修改此代码段。 My Wordpress is in the
domain.com/blog
directory. 我的Wordpress在
domain.com/blog
目录中。
You must say to the Host, that other files (like .htaccess
) is allowed to override rules. 您必须对主机说,允许其他文件(如
.htaccess
)覆盖规则。
Virtual Host 虚拟主机
<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>
Otherwise you can remove your complete blog-directives ( <Directory "/home/user/blog">
) and set the AllowOverride none
to AllowOverride All
: 否则,您可以删除完整的博客指令(
<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>
Than you can work with your rewriting on your .htaccess
( /home/user/blog/.htaccess
): 比起您可以在
.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>
Here, a little example from my site: 这是我网站上的一个小例子:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.