简体   繁体   English

带有 index.php 异常的 Htaccess 重写规则

[英]Htaccess Rewrite Rule with index.php exception

We have a website that redirects based on the URL string我们有一个基于 URL 字符串重定向的网站

Allow from all
RewriteEngine on
RewriteRule ^(.*)$ redir.php?j=$1 [R=301,L]

Where redir.php is an actual URL.其中 redir.php 是一个实际的 URL。 This htaccess file works great, however, I'd like to make an exception for index.php or the root URL.这个 htaccess 文件很好用,但是,我想为 index.php 或根 URL 做一个例外。 How can we modify the above htaccess to add the exception without disturbing the existing functionality?我们如何修改上面的 htaccess 以添加异常而不干扰现有功能?

Similar question: htaccess Rewrite path to subdomain except the Index Document - however we don't want to have a subdomain.类似的问题: htaccess 重写除索引文档之外的子域的路径- 但是我们不想有子域。 This is the root domain.这是根域。 I know we need a rewriteCond statement but we don't want to disturb the existing functionality.我知道我们需要一个 rewriteCond 语句,但我们不想打扰现有的功能。

You can try following redirect rule.您可以尝试遵循重定向规则。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^$ http://example.com/index.php [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ redir.php?j=$1 [R=301,L]

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

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