使用mod_rewrite可以在RewriteCond中指定RewriteBase吗? [英] With mod_rewrite can I specify a RewriteBase within a RewriteCond?

查看:76
本文介绍了使用mod_rewrite可以在RewriteCond中指定RewriteBase吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让我的.htaccess文件指定一个不同的RewriteBase,具体取决于该.htaccess文件是在我的本地计算机上还是在Web服务器上.这是我尝试的mod_rewrite代码,但是没有用:

I'd like to have my .htaccess file specify a different RewriteBase depending on whether the .htaccess file is on my local machine or on a web server. This is the mod_rewrite code I tried, however, it did not work:

RewriteCond %{HTTP_HOST} ^localhost:8080
RewriteBase /example/
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteBase /

这将很方便,因为它可以轻松地预览我的本地计算机上的多个网站,然后可以将这些网站上载到各个域名的Web服务器上.

This would come in handy for easily previewing several websites on my local machine and then being able to upload those sites to web servers for individual domain names.

推荐答案

我们最终找到的唯一解决方案是这样的:

The only solution we finally found looks like that :

# Activation of the URL Rewriting
Options +FollowSymlinks
RewriteEngine On

# RewriteBase equivalent - Production
RewriteCond %{HTTP_HOST} !^localhost$
RewriteRule . - [E=REWRITEBASE:/production/path/]

# RewriteBase equivalent - Development
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule . - [E=REWRITEBASE:/development/path/]

# Rewriting
RewriteRule ^(.*)$ %{ENV:REWRITEBASE}index.php?page=$1 [L]

此代码提供了一种模拟不同的"RewriteBase"的方法.

This code offers a way to simulate differents "RewriteBase".

这篇关于使用mod_rewrite可以在RewriteCond中指定RewriteBase吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆