我已经将我的主机更改为 1&1 windows 共享主机,其中重写在 Web 配置中被禁用,所说的在 htaccess 中实现
在我之前的托管中,如果用户输入 URL,它会喜欢 http://www.example.com/flowers1/flowers2/flowers3
然后页面内部调用 http://www.example.com/products.asp?catID=1&SubID=1&SubCatSubID=1(从不向用户显示)
这是有效的 webconfig 代码
<rule name="RewriteUserFriendlyURL" stopProcessing="true">
<match url="^flowers1/flowers2/flowers3/?$"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action url="products.asp?CatID=1&SubCatid=1&SubCatSubid=1" type="Rewrite"/>
</rule>
我想要 htaccess,我试试这个
RewriteCond %{QUERY_STRING} ^Catid=([0-9]*)
RewriteCond %{REQUEST_URI} ^/products\.asp
RewriteRule ^(.*)$ /flowers1/ [L,QSA]
要在具有共享主机的 Windows 主机环境中实现相同的功能,您需要修改网站的 web.config 文件。这是一个示例,说明如何修改规则以执行相同的操作:
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL" stopProcessing="true">
<match url="^flowers1/flowers2/flowers3/?$"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="/products.asp?CatID=1&SubCatid=1&SubCatSubid=1"/>
</rule>
</rules>
</rewrite>
此代码应添加到位于网站根目录的 web.config 文件中。如果该元素不存在,则应添加该元素。添加代码后,访问 URL http://www.example.com/flowers1/flowers2/flowers3 的用户应自动重定向到 http://www.example.com/products.asp?CatID= 1&SubCatid=1&SubCatSubid=1.