【问题标题】:Shorten Long URL using htaccess file使用 htaccess 文件缩短长 URL
【发布时间】:2013-05-10 10:31:58
【问题描述】:

我想使用 htaccess 缩短我的网址

http://mydomain.com/filename/categoryname/catid/subcategoryname/subid/productname/productid/

http://mydomain.com/productname/

一直在寻找如何实现这一目标的几个小时,但似乎没有任何效果。

【问题讨论】:

    标签: .htaccess url


    【解决方案1】:

    你尝试过 mod_rewrite 吗?

    RewriteEngine on
    RewriteMap shortcodes txt:/path/to/file/shortcodes.txt
    RewriteRule ^/(\d+)$ ${shortcodes:$1} [R=permanent,L]
    

    例如,在您的情况下,可能如下所示:

    productname  /filename/categoryname/catid/subcategoryname/subid/productname/productid/
    

    这应该放在 VirtualHost 定义中

    【讨论】:

    • 感谢 Hariprasad 的回复,我不是 mod_rewrite 方面的专家,你能向我解释一下 shortcodes.txt 的作用以及 /web/bens/ 是根路径吗
    • 您好,shortcodes.txt 是您需要根据您的域指定的映射文件。 url /web/bens/shortcodes.txt 将根据您的域而改变。也就是说,您存储此 shortcodes.txt 文件的位置。 RewriteMap shortcodes txt:path/to/file/shortcodes.txt 在这个文件中你需要指定这一行:productname /filename/categoryname/catid/subcategoryname/subid/productname/productid/
    • 为此干杯,我尝试将代码添加到我的 htaccesss 文件中,但给我一个 500 内部服务器错误,所以我询问了我的 ISP 是否可以更改 httpd.conf 文件跨度>
    猜你喜欢
    • 2015-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-22
    • 2012-03-27
    • 1970-01-01
    相关资源
    最近更新 更多