我一直在努力,在过去几个小时,在我的灯的机器写干净的URL。
I have been trying for the past few hours to write clean URLs in my LAMP machine.
Apache的mod_rewrite启用了,我想使用.htaccess文件的URL GET参数传递给我的index.php脚本,这在当时是_GET只是一个的var_dump。
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.
我目前的.htaccess是以下(虽然我已经试过它相当多的变化,我发现在其他的答案,但没有成功)
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]
当我指出我的浏览器到localhost / MY_PROJECT /测试,我得到的是一个404错误说:
When I point my browser to localhost/my_project/test, all I get is a 404 error saying:
未找到
所请求的网址/ MY_PROJECT /测试此服务器上找到。
The requested URL /my_project/test was not found on this server.
的Apache / 2.2.22(Ubuntu的)服务器在本地主机端口80
Apache/2.2.22 (Ubuntu) Server at localhost Port 80
显然,我缺少明显的东西在这里,任何帮助?
Apparently I'm missing something obvious here, any help?
2的事情,寻找:
确保的.htaccess启用 确保上述code是在 MY_PROJECT
目录。
Make sure .htaccess is enabled
Make sure above code is in my_project
directory.
然后添加的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]