Apache mod_重写域名

Apache mod_重写域名,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我在弄清楚如何使用mod rewrite对域名进行重写时遇到了一些问题。我认为这与域扩展有关,但不确定 Input: domain.com/google.com Callback: domain.com/index.php?website=google.com RewriteRule ^(.*)/$ index.php?website=$1 (.*)将匹配任何内容,因此尝试匹配域名并不重要。相反,问题似乎在于输入中不存在尾随斜杠/。只需删除它并使用^(.*)$。还建议添加[L]标志 Rewr

我在弄清楚如何使用mod rewrite对域名进行重写时遇到了一些问题。我认为这与域扩展有关,但不确定

Input: domain.com/google.com
Callback: domain.com/index.php?website=google.com

RewriteRule ^(.*)/$ index.php?website=$1
(.*)
将匹配任何内容,因此尝试匹配域名并不重要。相反,问题似乎在于输入中不存在尾随斜杠
/
。只需删除它并使用
^(.*)$
。还建议添加
[L]
标志

RewriteEngine On
# Avoid rewrite loops on real files like index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?website=$1 [L]
如果您需要选择性地包含尾部斜杠,请在输入字符串结尾前添加一个
,以匹配零或一个
/

RewriteRule ^(.*)/?$ index.php?website=$1 [L]

我很困惑,在为htaccess文件和PHP编写代码时,这是如何脱离主题的?