URL重写不在ubuntu中的localhost上工作

时间:2012-02-02 17:48:45

标签: php .htaccess url rewrite localhost

所以我在ubuntu 11.10上运行灯泡,我有以下问题

我需要这个网址: 本地主机/ MYNAME / oefeningenPHP / CMS /的index.php?头=约

重写为: 本地主机/ MYNAME / oefeningenPHP / CMS /约

网址有点乱,因为我有很多文件夹,上面有不同的PHP练习。

我的.htacces位于: 本地主机/ MYNAME / oefeningenPHP / CMS

因为cms是我的网站root。

.htacces包含以下代码:

<IfModule mod_rewrite.c>

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^/([a-z]+) /index.php?head=$1 

</IfModule>

但是返回404错误。

此外我确定正在加载重写模块,因为它在http.conf文件中没有注释

我的想法已经用完,所以我希望有人可以帮助我。我不太确定RewriteRule中的正斜杠,但我尝试了各种各样的东西,没有任何作用

2 个答案:

答案 0 :(得分:1)

尝试

RewriteRule ^([a-z]+) index.php?head=$1 [L]

您还应该看看是否通过向其添加一些垃圾来启用.htaccess,例如asdfasdfasdfasd,保存并尝试访问该网址。如果您没有收到500错误,则表示未启用。

要启用它,请查找显示

的行
AllowOverride None

并将其更改为

AllowOverride All

答案 1 :(得分:1)

如果您已经运行了sudo a2enmod rewrite命令,但您的URL Rewrite不起作用 要使.htaccess文件按预期工作,您需要编辑此文件:

Step1 : sudo vi /etc/apache2/sites-available/default

Step2 : Look for a section that looks like this: 
    <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
                # Uncomment this directive is you want to see apache2's
                # default start page (in /apache2-default) when you go to /
                #RedirectMatch ^/$ /apache2-default/
        </Directory>
You need to modify the line containing AllowOverride None to read AllowOverride All.
step 3 : sudo /etc/init.d/apache2 reload