我想要使用http://localhost/universe/networks/o2/o2_logo.gif之类的网址,然后执行以下操作:
If it begins with /universe/ Strip /universe/ from it to become /networks/o2/o2_logo.gif Check if this exists in %{DOCUMENT_ROOT}/networks/o2/o2_logo.gif If so, silently rewrite the request to this file.
如果我使用以下规则:
RewriteCond %{REQUEST_URI} ^/universe/ RewriteRule ^(.*)$ http://www.example.org/$1 [L]
http://localhost/universe/networks/o2/o2_logo.gif重新写入http://www.example.org/networks/o2/o2_logo.gif这很棒,但我似乎无法使用
我怎样才能进一步使用这个'更改'%{REQUEST_URI},比如1美元或者其他什么?
答案 0 :(得分:16)
我无法使用.htaccess纯粹使用以下文件:
RewriteEngine On
# Does the file exist in the content folder?
RewriteCond %{REQUEST_URI} !^/content.*
RewriteCond %{DOCUMENT_ROOT}/universe/%{REQUEST_URI} -f
# File Exists
RewriteRule ^ %{DOCUMENT_ROOT}/universe/%{REQUEST_URI} [L]
# If the request is not a file, link or directory then send to index.php
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L] # Item exists so don't rewrite
# Nothing exists for the request so append a trailing / if needed
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^ %{REQUEST_URI}/ [R=301,L]
RewriteRule ^.*$ index.php [NC,L] # Send off as-is to index.php
然后我进入了我的document_root文件夹并执行了以下操作:
cd /var/www/journal
ln -s journal/public universe
cd /var/www/journal/public
ln -s content/ universe
结合htaccess意味着一切正常。
答案 1 :(得分:1)
尝试此规则:
RewriteCond %{DOCUMENT_ROOT}$1 -f
RewriteRule ^universe/(.*) $1 [L]