ubuntu 14.04LTS apache2漂亮的url无法正常工作

时间:2015-06-26 23:10:57

标签: apache .htaccess ubuntu mod-rewrite

我一直在对着这堵墙撞了一会儿但没有成功。我做了很多次搜索,试图实现所有的建议,但仍然没有乐趣。我真的很感激为什么我的设置不起作用的任何建议。

我们刚刚设置了带有LAMP环境的Ubuntu 14.04LTS服务器,从那时起我一直试图让它与测试站点一起工作,这在我的本地XAMPP设置上运行得非常好。

以下是我的设置:

使用a2enmode重写启用mod_rewrite

更新/etc/apache2.conf文件以允许覆盖

<Directory /var/www/>
   Options Indexes FollowSymLinks
   AllowOverride All
   Require all granted
</Directory>

在/etc/apache2/sites-available/example.dev.conf中设置新的vhost

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/example.dev/public_html
    ServerName example.dev
    ServerAlias www.example.dev
    <Directory /var/www/example.dev/public_html>
        Options Indexes FollowSymLinks
        Require all granted
        AllowOverride all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

使用a2ensite example.dev.conf启用虚拟主机

将.htaccess文件从我的本地环境复制到/var/www/example.dev/public_html目录

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php !-f
    RewriteRule ^([^\.]+)/$ [NC,L]
</IfModule>
ErrorDocument 404 /404.php

最后用apache2 reload重新启动了apache

并且当我尝试进入辅助页面时,我最终会进入404页面。

我的网站设置为:

example.dev/index.php
    subdirectory
        file1.php
        file2.php
etc.

,链接是example.dev/subdirectory/file1.php

如果有人对如何完成这项工作有任何建议,我将不胜感激。

谢谢。

1 个答案:

答案 0 :(得分:0)

您的规则缺少目标网址,请将其用作:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)/?$ $1.php [L]