问题:当我在我的wordpress安装上启用非常永久链接时(因此,它使用/%postname%/),它不起作用.除主页外,我在所有页面上都获得了404.
这个页面http://codex.wordpress.org/Permalinks告诉我永久链接工作的要求:
>安装了mod_rewrite模块的Apache Web服务器
>在wordpress的主目录中,
>启用了FollowSymLinks选项
>允许FileInfo指令(例如AllowOverride FileInfo或AllowOverride All)
> .htaccess文件(如果缺少此文件,wordpress将在您激活“漂亮”永久链接时尝试创建它)
>如果您希望wordpress自动更新.htaccess文件,wordpress将需要对该文件的写访问权.
已经安装了Apache Web服务器,mod_rewrite模块已经加载了a2enmod rewrite命令(并且服务器已经多次重启).因此,在/ etc / apache2 / mods-enabled下,存在rewrite.load的符号链接.此外,当我运行PHPinfo命令时,我看到已加载mod_rewrite模块.你也可以在这里查看:http://namorti.com/phpinfo.php
然后,在/ etc / apache2 / sites-enabled中,没有“默认”存在.我将000-default.conf复制到默认值并在之后编辑默认值.它包含以下内容:
DocumentRoot / var / www
<Directory /> Options FollowSymLinks Indexes AllowOverride FileInfo </Directory>
因此,就我而言,已启用FollowSymLinks并允许使用FileInfo指令.
至于最后两点,在我的wordpress主目录(/ var / www)中,.htaccess存在并可由wordpress写入(我更新了永久链接结构几次,并相应地更新了.htaccess文件).现在它包含以下内容:
# BEGIN wordpress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.PHP$- [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.PHP [L] </IfModule> # END wordpress
所以,据我所知,它应该工作.我重启了服务器(service apache2 restart)几次.我不明白我错过了什么.有人在这里有线索吗?
提前致谢!
*编辑*
所以,我做了calcinai告诉我做的事情……我编辑了我的/ etc / apache2 / sites-enabled / default文件(包含vhost).它现在看起来像这样:
<VirtualHost *:80> # The ServerName directive sets the request scheme,hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts,the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However,you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin www.namorti.com DocumentRoot /var/www <Directory /var/www> Options MultiViews AllowOverride None Order allow,deny allow from all RewriteEngine On RewriteBase / RewriteRule ^index\.PHP$- [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.PHP [L] </Directory> # Available loglevels: trace8,...,trace1,debug,info,notice,warn,# error,crit,alert,emerg. # It is also possible to configure the loglevel for particular # modules,e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/,which are # enabled or disabled at a global level,it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost> # vim: Syntax=apache ts=4 sw=4 sts=4 sr noet
我又重新启动了apache,但不幸的是它仍然无效.老实说,这会让我感到惊讶,因为将.htaccess文件中的指令移动到vhost会起作用,如果htaccess本身可以工作,因为其他一切对我来说似乎都是正确的……
还有其他建议吗?谢谢你的努力!
更好的解决方案实际上是将重写指令放在vhost中,因为您显然拥有该文件的写入权限.当你打开AllowOverrides时,apache将在每个请求中查看目录和所有父目录中的.htaccess文件,这可能是一个很大的性能损失.
对于wordpress,您的vhost应该类似于:
<VirtualHost *:80> ServerName example.com DocumentRoot /var/www/site <Directory /var/www/site> Options Indexes FollowSymLinks AllowOverride None Order allow,deny allow from all RewriteEngine On RewriteBase / RewriteRule ^index\.PHP$- [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.PHP [L] </Directory> </VirtualHost>