微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐