【问题标题】:Apache rewrite - clean URLs in localhostApache 重写 - 本地主机中的清理 URL
【发布时间】:2013-10-13 06:11:50
【问题描述】:

过去几个小时我一直在尝试在我的 LAMP 机器中编写干净的 URL。

Apache 的 mod_rewrite 已启用,我正在尝试使用 .htaccess 文件将 URL GET 参数传递给我的 index.php 脚本,该脚本当时只是 _GET 的 var_dump。

我当前的 .htaccess 如下(尽管我已经尝试了很多变体,但在其他答案中没有成功)

RewriteEngine On

#Make sure it's not an actual file
RewriteCond %{REQUEST_FILENAME} !-f

#Make sure its not a directory
RewriteCond %{REQUEST_FILENAME} !-d 

#Rewrite the request to index.php
RewriteRule ^(.*)$ index.php?/get=$1 [L]

当我将浏览器指向 localhost/my_project/test 时,我得到的只是 404 错误:

找不到

在此服务器上找不到请求的 URL /my_project/test。

Apache/2.2.22 (Ubuntu) 服务器在 localhost 端口 80

显然我在这里遗漏了一些明显的东西,有什么帮助吗?

【问题讨论】:

  • 你也需要RewriteBase /,就在RewriteEngine On之后

标签: php regex apache .htaccess mod-rewrite


【解决方案1】:

要寻找的两件事:

  1. 确保 .htaccess 已启用
  2. 确保以上代码位于my_project 目录中。

然后添加RewriteBase 行:

RewriteEngine On
RewriteBase /my_project/

#Make sure it's not an actual file
RewriteCond %{REQUEST_FILENAME} !-f
#Make sure its not a directory
RewriteCond %{REQUEST_FILENAME} !-d 
#Rewrite the request to index.php
RewriteRule ^(.*)$ index.php?get=$1 [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-19
    • 2013-11-22
    • 2014-01-10
    • 1970-01-01
    相关资源
    最近更新 更多