在过去的几个小时里,我一直在尝试在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
显然我在这里遗漏了一些明显的东西,有什么帮助吗?
I have been trying for the past few hours to write clean URLs in my LAMP machine.
Apache's mod_rewrite is enabled, and I am trying to use an .htaccess file to pass the URL GET parameters to my index.php script which at the time is just a var_dump of _GET.
My current .htaccess is the following (although I've tried quite a few variations of it I found on other answers with no success)
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]When I point my browser to localhost/my_project/test, all I get is a 404 error saying:
Not Found
The requested URL /my_project/test was not found on this server.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80
Apparently I'm missing something obvious here, any help?
最满意答案
要寻找的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]2 things to look for:
Make sure .htaccess is enabled Make sure above code is in my_project directory.Then add RewriteBase line as well:
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]更多推荐
发布评论