的.htaccess错误:请求的URL没有此服务器

问题描述:

我有一个PHP文件,该文件是home.php的.htaccess错误:请求的URL没有此服务器

上找到

我在本地主机上的网址是

http://localhost:8888/photo/home.php

我想从删除.php网址

,所以我创建.htaccess文件

RewriteEngine On 

RewriteRule ^home?$ home.php 

但我不断收到此错误

请求的URL /照片/家在此服务器上找到。

+0

了''^手段开始在字符串的开始搜索。你可能想'^ /?照片/家' – Cfreak

+0

你好@Cfreak。谢谢你的回复,但是这也不管用'RewriteRule^/?photo/home home.php' –

+0

你可能需要使用这个:'RewriteRule ^(/?photo)/ home $ 1/home.php'。 '/ photo'需要在重写的URL中。反向引用的原因是,根据这个RewriteRule的位置,在匹配的URL的开头可能有也可能不是斜杠。 – Jost

像这样尝试,在你的照片目录中。

RewriteEngine On 

# neither a file nor a directory 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^home$ home.php [QSA,L] 

首先,确保您的.htaccess文件位于项目的基础目录中。接下来,按照these htaccess rules设置您的重定向。

你可能会寻找对的.htaccess的解决方案是:

RewriteEngine On 

#Neither a file nor a directory 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^photo/home$ photo/home.php [QSA,L]