过去几个小时我一直在尝试在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。
localhost端口80上的Apache / 2.2.22(Ubuntu)服务器
显然我错过了一些明显的东西,有什么帮助吗?
答案 0 :(得分:3)
要寻找的两件事:
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]