Apache重写

编程入门 行业动态 更新时间:2024-10-27 18:17:39
Apache重写 - 在localhost中清除URL(Apache rewrite - clean URLs in localhost)

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

更多推荐

本文发布于:2023-08-05 23:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1441420.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   Apache

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!