我需要一些帮助来编写.htaccess规则:
因此,服务器会将www.example.com/contact-us/456/789
等网址与www.example.com/contact-us.php?a=123&b=456&c=789
以下IIS web.config规则可以处理(使用重写映射):
<rule name="Dynamic Rewriting" stopProcessing="true">
<match url="^([^/]+)(?:/?([^/]+)?)(?:/?([^/]+)?)(?:/?([^/]+)?)/?$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{DynamicRewriting:{R:1}}" pattern="(.+)" />
</conditions>
<action type="Rewrite" url="/{C:1}.php?page={C:1}&a={R:2}&b={R:3}&c={R:4}" />
</rule>
<rewriteMap name="DynamicRewriting">
<add key="contact-us" value="contact-us" />
</rewriteMap>
有人能告诉我我需要的.htaccess规则吗?
答案 0 :(得分:1)
尝试:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/([^/]+)
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^/?([^/]+)(?:/?([^/]+)?)(?:/?([^/]+)?)(?:/?([^/]+)?)/?$ /$1.php?page=$1&a=$2&b=$3&c=$4 [L,QSA]