是否可以更改显示的 URL 与实际 URL 的不同?

发布于 2024-09-13 21:54:49 字数 585 浏览 3 评论 0原文

前几天我发布了一个关于如何更改 Wordpress 生成的页面上显示的 URL 的问题,特别是从“mysite.com/?cat=3”之类的内容更改为“mysite.com”。我收到了一些回复,引导我使用 .htacess 进行某种类型的重定向。经过一些研究和实验,我意识到我需要的并不是重定向,而只是改变浏览器中显示 URL 的某种方式。

部分挑战在于,相关页面是通过标准 WP 代码、WP 事件日历插件 (the-events-calendar) 和开发人员添加的一些自定义代码的组合动态生成的。我尝试过永久链接和类别标签,但无法获得所需的结果。

我认为更大的问题是:“网络服务器是否可以传递例如‘xyz.com/somedir/somefile.php?withsomequerystring=yes’,但指示浏览器显示 URL 为“xyz.com/pretty-url”?”

黑客似乎能够做出各种邪恶的事情,让人们认为他们在一个网页/网站上,而实际上他们在其他地方。我认为我所要求的可以通过 htaccess/mod_rewrite 实现,但我不知道如何实现它。几个星期以来,我一直在这个问题上苦苦思索,所以如果有人有好的建议,我会很高兴。

谢谢!

I posted a question the other day about how to change the displayed URL on a Wordpress-generated page, specifically from something like "mysite.com/?cat=3" to just "mysite.com". I got a few replies that steered me towards doing some type of redirect with .htacess. After some research and experimentation, I realized that it's not so much a redirect I need but just some way to alter the displayed URL in the browser.

Part of the challenge is that the page in question is dynamically generated by a combination of standard WP code, a WP event calendar plugin (the-events-calendar), and some custom code a developer added. I've played around with permalinks and the category slug, but I can't get the desired result.

The bigger question, I think, is: "Is it possible for a web server to deliver, for example, 'xyz.com/somedir/somefile.php?withsomequerystring=yes' but instruct the browser to show the URL as 'xyz.com/pretty-url' ?"

Hackers seem to be able to do all sorts of evil things to make people think they're on one web page/site when they're actually somewhere else. I would think what I'm asking is possible through htaccess/mod_rewrite, but I don't know how to achieve it. I've been banging my head against the wall on this for several weeks, so I would be thrilled if anyone had a good suggestion.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

掩于岁月 2024-09-20 21:54:49

使用永久链接

配置 WordPress 站点中的 URL 地址。访问仪表板,在设置下您将找到永久链接链接。

Use permalinks

To configure the URL address in a wordpress site. Visit the dashboard and under Settings you will find the Permalinks link.

满意归宿 2024-09-20 21:54:49

@webwiz:您可能会发现 这个答案是我 10 分钟前发布的,希望对您有所帮助。

我也许可以提供更多帮助,但我需要了解您的服务器上实际生成以下格式 URL 的内容:

http://xyz.com/somedir/somefile.php?withsomequerystring=yes

您想要转换为:

http://xyz.com/pretty-url

我想知道它们中是否有任何一个被路由我在另一篇文章中描述的任何 *_link 钩子?

@webwiz: You might find this answer I posted just 10 minutes ago to be helpful.

I might be able to help some more but I need to understand what it is on your server that actually generates the URLs for the following format:

http://xyz.com/somedir/somefile.php?withsomequerystring=yes

that you want converted to:

http://xyz.com/pretty-url

I'm wondering if any of them are routed through any of the *_link hooks I described in the other post?

太阳哥哥 2024-09-20 21:54:49

“网络服务器是否可以传递例如“xyz.com/somedir/somefile.php?withsomequerystring=yes”,但指示浏览器将 URL 显示为“xyz.com/pretty-url” ?”

您无法让浏览器显示与其所在的 URL 不同的 URL。但你能做的,
正如您已经说过的,是使用 mod_rewrite 在内部将 xyz.com/pretty-url 转换为您提到的 URL。

"Is it possible for a web server to deliver, for example, 'xyz.com/somedir/somefile.php?withsomequerystring=yes' but instruct the browser to show the URL as 'xyz.com/pretty-url' ?"

You can't make the browser show a different URL than the one it's on. But what you can do,
as you already say, is use mod_rewrite to internally translate xyz.com/pretty-url into the URL you mention.

吃兔兔 2024-09-20 21:54:49

我可能稍后会修改这个 - 我在工作。但我认为这并不太难。

我听说你想要做的是这样的:用户(更确切地说是浏览器)请求丑陋的 URL,你想要显示丑陋的 URL 上有什么,但您希望他们看到漂亮的网址。

简短的答案是将标头从丑陋的网址重定向到漂亮的网址,然后内部将漂亮的网址重写为丑陋的网址

您必须自己查找如何做这两件事,但它们并不难。此外,您还需要使标头重定向的优先级高于重写(将其放在 .htaccess 中的较高位置),或者使内部重写成为最后的重写(在 RewriteRule 之后放置 [l] 标志),以便重定向不会发生t 循环。

不过,您提到了很多自定义代码,通过此解决方案,该代码将看到该请求来自漂亮的 URL。 (相对脚本/图像/样式表引用将相对于漂亮的 URL 进行解析,但 Wordpress 中的相对 URL 将非常愚蠢。)

I may tinker with this later - I'm at work. But I think this isn't too hard.

What I'm hearing that you want to do is this: The user (the browser, rather) requests the ugly URL, you want to show what's at the ugly URL, but you want them to see the pretty URL.

The short answer is do a header redirect from the ugly url to the pretty url, and then do an internal rewrite of the pretty URL as the ugly URL.

You'll have to look up how to do those two things yourself, but they aren't hard. Also, you will want to either make the header redirect higher priority than the rewrite (place it higher up in .htaccess) or make the internal rewrite the last rewrite (put [l] flag after the RewriteRule), so that the redirects don't loop.

You mentioned lots of custom code, though, and with this solution, that code will see that request came from the pretty URL. (And relative script/image/stylesheet references will resolve relative to the pretty URL, but relative URLs in Wordpress would be very silly.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文