繁体   English   中英

.htaccess重写,其中URL基本名称与目录名称相同

[英].htaccess rewrite where url basename is same as a directory name

我的文件结构中有一个名为“ finder”的目录,我想重写一个以finder为基本名的URL。 例如,访问www.mysite.com/finder

这是我正在尝试的重写规则:

RewriteRule ^finder/?$ /finder/directory/listings.php [NC,L]

而不是成功重写,我收到了404 Page Not Found消息。 对于我值得的是,我有一个重写规则,该规则将这个URL用作该网址www.mysite.com/finder/california ...

RewriteRule ^finder/([a-zA-Z0-9+\-]*)/?$ /finder/directory/listings.php?s=$1 [NC,L]

..并且它正在工作。

我已经尝试过将DirectorySlash Off为我的.htaccess文件,但这也不起作用。 关于我所缺少的任何线索吗? 谢谢。

我看到两个潜在的麻烦领域:

  1. 具有此规则的htaccess文件不能位于finder文件夹中。 确保它在DOCUMENT_ROOT目录中。
  2. 重写中的正斜杠可能存在问题。

在Apache 2.2和2.4上测试:

  • RewriteRule ^finder/?$ directory/listings.php [NC,L]
  • 浏览器中的网址: http://www.example.com/finder : http://www.example.com/finder
  • 重定向到: http://www.example.com/directory/listings.php : http://www.example.com/directory/listings.php

让我知道这个是否奏效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM