在过去的几个小时里,我一直在尝试在我的 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 错误:
Not Found
The requested URL /my_project/test was not found on this server.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80
显然我在这里遗漏了一些明显的东西,有什么帮助吗?
最佳答案
要寻找的 2 件事:
- 确保 .htaccess 已启用
- 确保以上代码在
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]
关于php - Apache 重写 - 本地主机中的干净 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19211824/