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

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

问题描述

我想让我的 .htaccess 文件指定不同的 RewriteBase,具体取决于 .htaccess 文件是在我的本地机器上还是在网络服务器上.这是我尝试过的 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 /

这将派上用场,可以轻松地在我的本地机器上预览多个网站,然后能够将这些网站上传到各个域名的网络服务器.

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天全站免登陆