问题描述
我如何能捕捉与国防部重写一个完全合格的本地URL路径?
How can I capture a fully qualified local URL path with mod rewrite?
例如,我的项目位于的http:// {本地主机} /projects/mywebsite/index.php
我试着用这个的RewriteBase /项目/ mywebsite /
,但它并不适用于的ErrorDocument
工作
I tried with this RewriteBase /projects/mywebsite/
but it does not work for ErrorDocument
.
我的.htaccess,
my .htaccess,
RewriteEngine on
RewriteBase /projects/mywebsite/
ErrorDocument 404 /error.php
我需要做的的ErrorDocument 404 /projects/mywebsite/error.php
,但它不是动态的。我不得不每次改变它在两个地方为每一个项目。
I need to do ErrorDocument 404 /projects/mywebsite/error.php
but it isn't dynamic. I have to change it in two places everytime for each project.
任何想法?
推荐答案
的ErrorDocument
不接受不同于的mod_rewrite $ C任何ENV变量$ C>规则。这里是你可以做的:
ErrorDocument
doesn't accept any env variable unlike mod_rewrite
rules. Here is what you can do:
- 而不是
的ErrorDocument
使用的mod_rewrite
规则来处理404问题(见下文) - 生成
的RewriteBase
值动态地使用规则
- Instead of
ErrorDocument
usemod_rewrite
rules to handle 404 issues (see below) - Generate
RewriteBase
value dynamically using rules
您可以在您的根目录的.htaccess使用code:
You can use this code in your root .htaccess:
RewriteEngine On
RewriteBase /
# Determine the RewriteBase automatically/dynamically
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]
# use %{ENV:BASE} variable set above for routing file/dir not found
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . %{ENV:BASE}error.php?e=404 [L,QSA]
这篇关于我怎样才能捕捉与国防部重写完全合格的本地URL路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!