使用.htaccess文件中的mod_rewrite缩短URL

时间:2011-12-28 16:16:30

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

基本上我想做的就是:

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

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

现在我要删除网址的这一部分:

/Study%20notes/Atlantean%20Realities/

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

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

我是新来的!你可能会在上面看到:)我必须保持服务器上的目录布局,所以我唯一的选择是使用mod_rewrite吗?

1 个答案:

答案 0 :(得分:0)

尝试将以下内容添加到域

的根文件夹中的.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]