英文:
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:
<?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>
答案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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论