PHP-Apache Rewrite-本地主机中的干净URL

在过去的几个小时中,我一直试图在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

显然我在这里缺少明显的东西,有帮助吗?

解决方法:

有两件事情要寻找:

>确保已启用.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]

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...