21 mod-rewrite
我想让我的.htaccess文件指定一个不同的RewriteBase,具体取决于.htaccess文件是在我的本地机器上还是在Web服务器上.这是我尝试过的mod_rewrite代码,但它不起作用:
RewriteCond %{HTTP_HOST} ^localhost:8080
RewriteBase /example/
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteBase /
Run Code Online (Sandbox Code Playgroud)
这样可以方便地在我的本地计算机上预览多个网站,然后将这些网站上传到Web服务器以获取单个域名.
小智 30
我们最终找到的唯一解决方案如下:
# 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]
Run Code Online (Sandbox Code Playgroud)
此代码提供了一种模拟不同"RewriteBase"的方法.
| 归档时间: |
|
| 查看次数: |
12902 次 |
| 最近记录: |