【发布时间】:2014-07-17 08:23:07
【问题描述】:
第一次在这里使用 mod_rewrite 我有这个规则在 IIS 上工作:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="services" stopProcessing="true">
<match url="^([a-z]+)/service/([a-zA-Z-]+)" />
<action type="Rewrite" url="serveis.php?id={R:2}&lang={R:1}"/>
</rule>
<rule name="categories" stopProcessing="true">
<match url="^([a-z]+)/category/([a-zA-Z-]+)" />
<action type="Rewrite" url="subhome.php?id={R:2}&lang={R:1}"/>
</rule>
<rule name="index_idioma" stopProcessing="true">
<match url="^([a-z]+)/index" />
<action type="Rewrite" url="index.php?lang={R:1}"/>
</rule>
<rule name="index" stopProcessing="true">
<match url="http://www.domain.com" />
<action type="Rewrite" url="http://www.domain.com/index.php?lang=en"/>
</rule>
<rule name="kinds" stopProcessing="true">
<match url="^([a-z]+)/kind" />
<action type="Rewrite" url="tipusserveis.php?lang={R:1}"/>
</rule>
<rule name="company" stopProcessing="true">
<match url="^([a-z]+)/our_company" />
<action type="Rewrite" url="/empresa.php?lang={R:1}" />
</rule>
<rule name="contact" stopProcessing="true">
<match url="^([a-z]+)/contact" />
<action type="Rewrite" url="/contacto.php?lang={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
现在我想使用 apache 的 mod_rewrite 来实现,我试过这个:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/([a-z]+) index.php?lang=$1 [NC,L]
RewriteRule ^/([a-z]+)/our_company/?$ empresa.php?lang=$1 [NC,L]
RewriteRule ^/([a-z]+)/contact/?$ contacto.php?lang=$1 [NC,L]
RewriteRule ^/([a-z]+)/service/([A-Za-z0-9-]+)/?$ serveis.php?id=$2&lang=$1 [NC,L]
RewriteRule ^/([a-z]+)/category/([A-Za-z0-9-]+)/?$ subhome.php?id=$2&lang=$1 [NC,L]
RewriteRule ^/([a-z]+)/kind/([A-Za-z0-9-]+)/?$ tipusserveis.php?id=$2&lang=$1 [NC,L]
</IfModule>
但它们都不起作用。
有人可以在这里帮助我吗,至少给我一些关于我应该怎么做的方向?
编辑:
Plesk Panel 自动将此添加到httpd.conf
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com$1 [L,R=301]
<IfModule>
我猜它会从 URL 中删除 www,但我不知道它是否也会停止应用其他规则。 谢谢
【问题讨论】:
标签: apache .htaccess mod-rewrite iis web-config