.htaccess问题-需要提取新的重写基并将文件名替换为变量

.htaccess问题-需要提取新的重写基并将文件名替换为变量,.htaccess,url,mod-rewrite,substitution,.htaccess,Url,Mod Rewrite,Substitution,我有3个可能的位置可以查看一个网站- http://localhost/mysite http://myhost.com/webs/mysite (for demos prior to publishing) http://clienturl.com 这些文件使用一个简单的PHP模板系统,因此通常情况下,任何给定内容的完整URL都是- 然而,我想做的是 解析,以便将单词“contact”放在变量“pg”中 这可以与这个.htaccess指令配合使用- RewriteRule (.*)\.h

我有3个可能的位置可以查看一个网站-

http://localhost/mysite
http://myhost.com/webs/mysite  (for demos prior to publishing)
http://clienturl.com
这些文件使用一个简单的PHP模板系统,因此通常情况下,任何给定内容的完整URL都是-

然而,我想做的是

解析,以便将单词“contact”放在变量“pg”中

这可以与这个.htaccess指令配合使用-

RewriteRule (.*)\.html index.php?pg=$1 [QSA] # 
它在本地和myhost.com上运行良好

但是,当放置在clienturl.com上时,除了根以外的任何页面:
clienturl.com

导致服务器错误,类似于“找不到文件”

所以我发现我可以指定一个环境变量

.htaccess

事实证明clienturl.com需要为REWRITEBASE指定“/”,尽管据我所知,.htaccess应该允许相对URL,而不需要显式指定

这适用于除我的Web服务器之外的所有地区,直到我在URL前面放了一个WWW,因为我认为是一个指令从我自己的服务器的根文件夹处理WWW

所以我试过这个-

.htaccess

这在本地工作,在我的Web服务器上工作,这意味着contact.html在URL栏中显示为contact.html(即使URL前面有一个WWW),但在clienturl.com上,URL恢复为index.php?pg=contact

我很困惑,我真的希望能有人帮助我理解我做错了什么

谢谢大家的帮助

#0 http://stackoverflow.com/questions/869092/how-to-enable-mod-rewrite-for-apache-2-2 0#
# Tell PHP that the mod_rewrite module is ENABLED.
#0 --------------------------------------------- 0#
SetEnv HTTP_MOD_REWRITE On
#0 --------------------------------------------- 0#

# Determine REWRITEBASE #
#1 http://stackoverflow.com/questions/2045897/with-mod-rewrite-can-i-specify-a-rewritebase-within-a-rewritecond 1#
#1 https://www.webmasterworld.com/apache/3522649.htm 1#
#1 --------------------------------------------- 1#
# Activation of the URL Rewriting
Options +FollowSymlinks
RewriteEngine On

# RewriteBase equivalent - NOT portal2web.biz or local
RewriteCond %{HTTP_HOST} !^portal2web.biz$ [OR]     
RewriteCond %{HTTP_HOST} !^localhost$
RewriteRule . - [E=REWRITEBASE:/]


# RewriteBase equivalent - portal2web.biz or local
RewriteCond %{HTTP_HOST} ^portal2web.biz$ [OR]  
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule . - [E=REWRITEBASE:]

#1 --------------------------------------------- 1#

# The rest of your rewrite rules here

# rules should be written most complicated to least complicated, structurally
RewriteRule (.*)\.html %{ENV:REWRITEBASE}index.php?pg=$1 [QSA] # 
# http://stackoverflow.com/questions/869092/how-to-enable-mod-rewrite-for-apache-2-2 #
# Tell PHP that the mod_rewrite module is ENABLED.
# --------------------------------------------- #
SetEnv HTTP_MOD_REWRITE On
# --------------------------------------------- #

# Determine REWRITEBASE #
# http://stackoverflow.com/questions/2045897/with-mod-rewrite-can-i-specify-a-rewritebase-within-a-rewritecond #
# https://www.webmasterworld.com/apache/3522649.htm #
# Activation of the URL Rewriting
Options +FollowSymlinks
RewriteEngine On

# check for http:// or https:// and set environment variable HTTP #
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ - [E=HTTP:http://]

RewriteCond %{HTTPS}:s on:(s) 
RewriteRule ^(.*)$ - [E=HTTP:https://]

# define environment variable REWRITEBASE #
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=REWRITEBASE:%{ENV:HTTP}%{HTTP_HOST}%1]

# rewrite to get proper variable format for index #
# rules should be written most complicated to least complicated, structurally
RewriteRule (.*)\.html index.php?pg=$1 [QSA] #