htaccess的重写规则preventing无限循环重写、规则、htaccess、preventing

2023-09-02 20:36:23 作者:级尽妖娆

我有一个名为目录的美元的包含文件中的的index.php 的。我想对URL的的http://本地主机/美元/富的翻译成的美元/ index.php的美元=富的?这是.htaccess文件,我现在已经在美元的directorty:

I have a directory named dollars that contains a file index.php. I would like for the url http://localhost/dollars/foo to translate to dollars/index.php?dollars=foo. This is the .htaccess file that I currently have in the dollars directorty:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !^index.php
RewriteRule ^(.+)$ index.php?dollars=$1 [L]

这个想法是不是一个请求之外的任何请求的的index.php 的应该使用重写规则。

The idea being that any request other than a request to index.php should use the RewriteRule.

不过,这是行不通的。

我一直在寻找了一段时间试图找出如何创造我想要的重定向,但我不知道如果我在正确的轨道。正则表达式从来都不关我的事。感谢您的帮助!

I've been looking for a while trying to figure out how to create the redirect I want, but I don't even know if I'm on the right track. Regex were never my thing. Thanks for any help!

推荐答案

有关重写一个常用的解决方法就是检查被请求不指向一个实际的文件/目录的路径,并改写它,如果它不T - 因为重写URL然后将指向实际的文件,没有环路发

A often-used solution for rewrites is to just check that the path being requested doesn't point to an actual file/directory, and rewrite it if it doesn't - since the rewritten URL will then point to an actual file, no loop occurs.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d