在RewriteCond指令文件中使用涂改%{REQUEST_URI}存在检查 [英] Using altered %{REQUEST_URI} in RewriteCond file exists check
问题描述
我想采取一个URL,如<一个href="http://localhost/universe/networks/o2/o2_logo.gif">http://localhost/universe/networks/o2/o2_logo.gif然后执行以下操作:
I'm wanting to take a URL such as http://localhost/universe/networks/o2/o2_logo.gif and do the following:
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]
<一个href="http://localhost/universe/networks/o2/o2_logo.gif">http://localhost/universe/networks/o2/o2_logo.gif被重新写入<一个href="http://www.example.org/networks/o2/o2_logo.gif">http://www.example.org/networks/o2/o2_logo.gif这是伟大的,但我似乎无法使用
http://localhost/universe/networks/o2/o2_logo.gif gets re-written to http://www.example.org/networks/o2/o2_logo.gif which is great, but I can't seem to use the
如何去使用这种改变%{REQUEST_URI}进一步下跌的说,$ 1或东西?
How can I go about using this 'changed' %{REQUEST_URI} further down as say $1 or something?
推荐答案
我是不是能够得到这个权利与纯粹的.htaccess,但采用了以下文件:
I was not able to get this right purely with .htaccess but used the following file:
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文件夹,并做了以下内容:
Then I went into my document_root folder and did the following:
cd /var/www/journal
ln -s journal/public universe
cd /var/www/journal/public
ln -s content/ universe
这是结合htaccess的意味一切工作。
That combined with the htaccess meant everything was working.
这篇关于在RewriteCond指令文件中使用涂改%{REQUEST_URI}存在检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!