繁体   English   中英

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

[英]URL Rewrite not working on localhost in ubuntu

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

我需要这个网址:localhost / myname / oefeningenPHP / cms / index.php?head = about

改写为:localhost / myname / oefeningenPHP / cms / about

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

我的.htacces位于:localhost / 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中的正斜杠,但我尝试了各种各样的东西,没有任何作用

如果您已经运行了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

尝试

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

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

要启用它,请查找说明的行

AllowOverride None

并将其更改为

AllowOverride All

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM