【问题标题】:shorten URL with mod_rewrite in .htaccess file在 .htaccess 文件中使用 mod_rewrite 缩短 URL
【发布时间】:2011-12-28 16:16:29
【问题描述】:

基本上我想做的就是:

我在此位置的服务器上有一个 PDF 文件的 URL:

http://chudz.co.uk/philaletheians.co.uk/Study%20notes/Atlantean%20Realities/Atlantis'%20study%20-%20Appendices%20and%20Notes.pdf

现在我想删除这部分 URL:

/Study%20notes/Atlantean%20Realities/

这是我在 htaccess 文件中所做的,但它不起作用:

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^/ /Study%20notes/Atlantean%20Realities/

我是新手!正如您可能在上面看到的那样:)我必须保持服务器上的目录布局,所以我唯一的选择是使用 mod_rewrite 也许?

【问题讨论】:

    标签: .htaccess url mod-rewrite url-rewriting


    【解决方案1】:

    尝试将以下内容添加到域根文件夹中的 .htaccess 文件中

    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /
    
    #if request does not already start with /Study notes/Atlantean Realities/
    RewriteCond %{REQUEST_URI}  !^/Study\ notes/Atlantean\ Realities/ [NC]
    #rewrite it to the /Study%20notes/Atlantean%20Realities/ directory
    RewriteRule (.*) /Study\ notes/Atlantean\ Realities/$1 [L]
    

    【讨论】:

    • 您好,我已经尝试了上述方法,但我只是收到内部服务器错误 500。
    • 我在上面进行了编辑,以逃避目录和 url 中的空格,如果可以的话,你应该摆脱它们
    猜你喜欢
    • 2015-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多