【问题标题】:URL Rewrite not working on localhost in ubuntuURL重写在ubuntu中的localhost上不起作用
【发布时间】:2012-02-02 17:48:44
【问题描述】:

所以我在 ubuntu 11.10 上运行 Lampp,我遇到了以下问题

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

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

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

我的 .htacces 位于: localhost/myname/oefeningenPHP/cms

因为 cms 是我的站点根目录。

.htacces 包含以下代码:

<IfModule mod_rewrite.c>

Options +FollowSymLinks
RewriteEngine on

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

</IfModule>

但返回 404 错误。

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

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

【问题讨论】:

  • 正则表达式根本不匹配 url
  • 删除 标签。他们没用。如果它给出 500 错误,则您没有激活 url 重写。
  • De slash aan het begin van de expressie moet je weglaten.

标签: php .htaccess url rewrite localhost


【解决方案1】:

试试

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

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

要启用它,请寻找一行显示

AllowOverride None

并将其更改为

AllowOverride All

【讨论】:

  • 如果没有斜线,它会通过 erver 错误,但现在我得到了一些 php 错误。这是因为 get 参数不再传递了吗?
  • @user1185774 我不这么认为,但是您可以通过直接转到 url 来确认,即如果localhost/myname/oefeningenPHP/cms/index.php?head=about 给您同样的错误,那么它与 .htaccess 规则无关跨度>
【解决方案2】:

如果您已经运行 sudo a2enmod rewrite 命令,但您的 URL 重写不起作用。
要使 .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

【讨论】:

    猜你喜欢
    • 2013-12-16
    • 1970-01-01
    • 1970-01-01
    • 2012-01-25
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    • 2012-12-23
    • 2012-10-09
    相关资源
    最近更新 更多