2016-05-16 40 views
2

URL重写不工作,a2enmod活跃,利用覆盖所有的,正确的.htaccess

我已经安装了一个WordPress的问题。我打开了漂亮的固定链接(帖子名称)。主页以外的任何页面都是404 Not Found。这似乎表明一个重写问题。

我的设置

Ubunutu 14.04 使用localhost作为我的URL 我的Apache配置是/etc/apache2/sites-available/000-default.conf 我的WordPress位于/var/www/wordpress/ 我有关的htaccess位于/var/www/wordpress/.htaccess

我”什么已经试过

当我运行a2enmod rewrite我得到

Module rewrite already enabled 

.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 

000-default.conf文件的Apache配置

<Directory /var/www/wordpress/> 
    Options Indexes FollowSymLinks MultiViews 
    AllowOverride All 
    Order allow,deny 
    allow from all 
</Directory> 

我已经尝试了所有的答案,在这个规范的问题。

How to enable mod_rewrite for Apache 2.2

我的问题

为什么不工作我重写?

+0

您的Apache版本是2.2吗? –

+0

检查'apache2ctl -t -D DUMP_MODULES'和'apache2ctl -t -D DUMP_VHOSTS',另请参阅您的日志文件。将相关输出添加到您的问题。 –

回答

1

检查正确的虚拟主机配置的步骤: 检查“站点可用”目录中是否存在“vhostname.conf”文件。然后检查“sites-enabled”目录中是否存在有效的符号链接。您可以通过a2ensite vhostname创建缺少的站点符号链接。在编辑器中打开此文件。它应该包含这样的

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName sitename.net 
    ServerAlias www.site-name.net 

    DocumentRoot /var/www/site-folder/htdocs 

    <Directory /var/www/site-folder/htdocs/> 
      Options Indexes FollowSymLinks MultiViews 
      DirectoryIndex index.php7 index.php5 index.php index.html 
      AllowOverride All 

# apache 2.2 and below only (following 3 lines) 
      Order allow,deny 
      Allow from all 
      Deny from none 

# apache 2.4 only 
      Require all granted 
    </Directory> 

确保DocumentRoot文件夹中有一个匹配<Directory /path/to/docroot>块。放入此块AllowOverride All或您希望允许在“.htaccess”中覆盖的任何选择性权限。

确保重写模块已启用。

sudo a2enmod rewrite 

修改配置后不要忘记重新启动/重新加载Apache。

sudo apache2ctl graceful 

检查模块和vhost配置是否已加载。

apache2ctl -t -D DUMP_VHOSTS 
apache2ctl -t -D DUMP_MODULES 
1

我发现,我需要在/etc/apache2/apache2.conf编辑Apache的配置,改变/var/www/目录到AllowOverride All

<Directory /var/www/> 
    Options Indexes FollowSymLinks MultiViews 
    AllowOverride All 
    Order allow,deny 
    allow from all 
</Directory> 

我本来以为我000-default.conf将有凌驾于这但事实并非如此,这固定问题。

+0

我的apache2.conf在'/'和'/ var/www'设置为'None',重写工作正常。 –

+0

@ Quasimodo'sclone同意它是意想不到的,但它解决了我的问题,我没有在StackOverflow上看到这个问题的答案,所以这可能对别人有帮助。 – Goose

+0

这个答案已经发布在[question](http://stackoverflow.com/questions/869092/how-to-enable-mod-rewrite-for-apache-2-2)你已经链接(37 upvotes) 。它似乎解决了配置问题,但是,这是一个奇怪的行为(不是没有工作),我不想在生产系统上进行这样的设置。 –