首页 > 解决方案 > Wordpress 类型 htaccess 如果是 url 有条件使用此规则?

问题描述

我有这个代码;

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$  $1/ [R]

# Send all remaining (routable paths) through index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Determine and use the actual base
RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
RewriteRule ^.*$ %2indexsef.php [QSA,L]

我想在脚本之外使用替代 sef 端,但我不知道起始行..

如果网址有“/announcements/ ”或“/contact/ ”或“/contact”或blabla使用;

RewriteRule ^.*$ %2other.php [QSA,L]

我怎样才能做到这一点?

标签: php.htaccessrules

解决方案


RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$  $1/ [R]

#insert new rules here
RewriteCond %{REQUEST_URI} "(^/announcements|/contact)" [NC]
RewriteRule gotothisfile.php

# Send all remaining (routable paths) through index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Determine and use the actual base
RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$
RewriteRule ^.*$ %2indexsef.php [QSA,L]

RewriteCond 的一个常用规则是检查它是否以某些东西开头。您可以通过将 ^ 放在开头来做到这一点。在您的示例中, /contact/ 和 /contact 都以相同的字母开头,因此您无需单独处理它们。

管道字符 | 用于允许匹配不同的单词。

确保不要将 $ 放在规则的末尾,因为这意味着“url 结束”


推荐阅读