简体   繁体   English

如何将带有附加参数的大网址变成较小的网址?

[英]How do I make a big url into a smaller url with appended parameters?

Here is my problem. 这是我的问题。

I have a complex url - Example: www.mywebsite.com/first/second/something/index.html 我有一个复杂的网址-例如:www.mywebsite.com/first/second/something/index.html

And i want to convert it into something like www.mywebsite.com/index.html?a=64&e=453 我想将其转换为www.mywebsite.com/index.html?a=64&e=453

I have seen this in some websites. 我已经在一些网站上看到了。

But I am not able to figure out how that is done. 但是我不知道该怎么做。 Any help will be appreciated. 任何帮助将不胜感激。

Those URLs are generated by a server-side programming language, like PHP. 这些URL由服务器端编程语言(如PHP)生成。 The pages are generated dynamically, and are typically not desirable (because 'clean' URLs are easier to read and edit and better for SEO). 页面是动态生成的,通常是不理想的(因为“干净” URL更易于阅读和编辑,并且更适合SEO)。

Technically, you can add ?a=64 to a regular web address and it won't prevent the page from rendering - but I'm not sure why anyone would want to do this. 从技术上讲,您可以在常规网址中添加?a=64 ,它不会阻止页面呈现-但我不确定为什么有人会这样做。

The answer would most likely depend on what web server you are using. 答案很可能取决于您所使用的Web服务器。 If you are using Apache, you can do this with mod_rewrite. 如果您使用的是Apache,则可以使用mod_rewrite进行此操作。 You can find a lot of documentation on exactly how to set this up online: 您可以找到很多有关如何在线设置的文档:

http://httpd.apache.org/docs/current/mod/mod_rewrite.html https://www.sitepoint.com/apache-mod_rewrite-examples/ http://httpd.apache.org/docs/current/mod/mod_rewrite.html https://www.sitepoint.com/apache-mod_rewrite-examples/

For example, if you wanted to map a URL parameter to a path you could do something like 例如,如果您想将URL参数映射到路径,则可以执行以下操作

RewriteCond %{QUERY_STRING}     a=64    [NC]
RewriteRule ^/index.html$       /first/second/something/index.html      [NC,L,R=301]

(I haven't tried that out, so the syntax might not be 100% correct.) But then you'd have to manually create a rule for every number to path mapping that you want, which might be a lot of work, so this might not be the best solution. (我还没有尝试过,所以语法可能不是100%正确的。)但是,您必须手动为每个数字创建规则,以实现所需的路径映射,这可能需要很多工作,因此这可能不是最佳解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM