我想在我的网站上更改我的网址。我读了一些文章,现在,我知道如何重写这样的urls:
用户输入地址栏=> www.example.com/Q1
加载页面为=> www.example.com/dir1 1/cat.aspx?id=q1
但我想要这个:
用户输入地址栏=> www.example.com/dir1 1/cat.aspx?id=q1
浏览器在地址栏中显示=> www.example.com/othername/Q1
有什么办法吗?
这是我关于重写的webconfig的一部分:
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite page to aspx" stopProcessing="true">
<match url="^([a-z0-9/]+)$" ignoreCase="false" />
<action type="Rewrite" url="{R:1}.aspx" />
</rule>
</rules>
<rule name="Rewrite item ID" stopProcessing="true">
<match url="^items/([0-9]+)$" ignoreCase="false"/>
<action type="Rewrite" url="items.aspx?id={R:1}"/>
</rule>
<rule name="Redirect to clean URL" stopProcessing="true">
<match url="^([a-z0-9/]+).aspx$" ignoreCase="true"/>
<action type="Redirect" url="{R:1}"/>
</rule>
</rewrite>
发布于 2014-10-06 11:32:52
我找不到真正的答案。但是,我找到了一种简单的方法来重写我的urls,而没有任何设置和模块,这部分解决了我的问题:
您可以用global.asax重写:
void Application_BeginRequest(Object sender, EventArgs e)
{
String strCurrentPath;
String strCustomPath;
strCurrentPath = Request.Path;
if ( strCurrentPath.EndsWith("/home/"))
{
strCustomPath = strCurrentPath.Replace("/home/", "/presentation/default.aspx");
Context.RewritePath(strCustomPath);
return;
}
else
{
if (strCurrentPath.Contains("/dir1/"))
{
strCustomPath = strCurrentPath.Replace("/dir1/", "/othername/cat.aspx?cid=");
Context.RewritePath(strCustomPath);
return;
}
}
}发布于 2014-10-02 06:15:49
如果您正在使用apache,则可以通过将以下内容添加到.htaccess文件中来完成:
RewriteEngine on
# check if the query string contains an `id` equal to `Q1`
RewriteCond %{QUERY_STRING} id=Q1
# rewrite `dir1/cat.aspx` to `othername/Q1`
RewriteRule dir1/cat.aspx http://www.example.com/othername/Q1? [R=301,L]对于web.config文件,上面的内容应该如下所示:
<rule name="rule 1k" stopProcessing="true">
<match url="dir1/cat.aspx" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="^id=Q1" />
</conditions>
<action type="Redirect" appendQueryString="false" url="http://www.example.com/othername/Q1" />
</rule>参考资料
重写
将.htaccess内容转换为IIS web.config
发布于 2016-01-12 16:49:18
您可以使用IIS重写。
这是您需要安装的另一个模块。一旦您安装了它,您可以在仪表板上找到它。从这里开始,添加一个规则将传入的URL更改为所需的URL。
这里有一个很棒的指南:https://www.youtube.com/watch?v=hkEFPzixiVE
https://stackoverflow.com/questions/26155130
复制相似问题