如何将域名后的路径更友好?

huangapple go评论66阅读模式
英文:

How to change the path after a domain to be more friendly?

问题

可以在浏览器地址栏中更改域名后的路径吗?

例如,我在www.mydomain.com上,通过点击链接跳转到www.mydomain.com/path/another_path/

如何将其更改为www.mydomain.com/new_path

谢谢帮助。

英文:

Is it possible to change the path after a domain in the browser address bar?

for example, I am on www.mydomain.com and by hitting a link it goes to www.mydomain.com/path/another_path/.

How can I change this to www.mydomain.com/new_path

Thanks for helping.

答案1

得分: 0

你可以在项目的 web.config 文件中使用 URL 重写规则来实现这个目标:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Rewrite">
          <match url="path/another_path" />
          <action type="Rewrite" url="https://example.com/new_path" />
        </rule>
      </rules>
    </rewrite>
    <defaultDocument>
      <files>
        <clear />
        <add value="index.html" />
        <add value="Default.htm" />
        <add value="Default.asp" />
        <add value="index.htm" />
        <add value="iisstart.htm" />
        <add value="default.aspx" />
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>
英文:

You should be able to accomplish this with a URL Rewrite rule in your project web.config file:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;configuration&gt;
  &lt;system.webServer&gt;
    &lt;rewrite&gt;
      &lt;rules&gt;
		&lt;rule name=&quot;Rewrite&quot;&gt;
			&lt;match url=&quot;path/another_path&quot; /&gt;
			&lt;action type=&quot;Rewrite&quot; url=&quot;https://example.com/new_path&quot; /&gt;
		&lt;/rule&gt;
  &lt;/rules&gt;
    &lt;/rewrite&gt;
        &lt;defaultDocument&gt;
            &lt;files&gt;
                &lt;clear /&gt;
                &lt;add value=&quot;index.html&quot; /&gt;
                &lt;add value=&quot;Default.htm&quot; /&gt;
                &lt;add value=&quot;Default.asp&quot; /&gt;
                &lt;add value=&quot;index.htm&quot; /&gt;
                &lt;add value=&quot;iisstart.htm&quot; /&gt;
                &lt;add value=&quot;default.aspx&quot; /&gt;
            &lt;/files&gt;
        &lt;/defaultDocument&gt;
  &lt;/system.webServer&gt;
&lt;/configuration&gt;

答案2

得分: 0

这取决于你的实现或你正在使用的项目/框架。

首先要检查的是,你正在使用的框架是否提供了url_rewrite功能

如果你是从头开始编码并且可以编辑服务器配置,比如Apache/Nginx,那么你可以配置从新的URL到旧的URL的3xx重定向,如下所示:

对于Nginx,请参考:https://www.nginx.com/blog/creating-nginx-rewrite-rules/

对于Apache,请参考:https://httpd.apache.org/docs/2.4/rewrite/remapping.html

英文:

It depends on your implementation or the project/framework you are using.

First thing to check is, does the framework you are using provide an url_rewrite feature.

If you are coding from scratch and that you can edit server config like apache/nginx then you can configure a 3xx redirect from new to old url like below :

For nginx see : https://www.nginx.com/blog/creating-nginx-rewrite-rules/

For apache : https://httpd.apache.org/docs/2.4/rewrite/remapping.html

huangapple
  • 本文由 发表于 2020年1月6日 22:12:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/59613611.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定