使用htaccess将参数传递给子域上的PHP

时间:2018-07-14 04:29:00

标签: apache mod-rewrite

因此,我有一个运行WordPress的域(example.com)和一个没有运行的子域(u.example.com)。子域的文件存储在example.com/u中。我正在尝试使用斜杠将参数传递给我的子域。例如:u.example.com/sometext将由u.example.com/index.php?par=sometext处理。我一直在搜索并尝试不同的方法,但无法使其与子域一起使用。

这是我的代码:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^u\.example\.com$ [NC]
RewriteRule ^/?(.*)\/? u\/index.php?par=$1 [R=301,L]

1 个答案:

答案 0 :(得分:0)

我能够使用以下方法解决我的问题:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^u\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^/?(.*)\/? \/index.php?par=$1 [R=301,L]

最初,它会使我陷入无限循环,因此添加了RewriteCond %{REQUEST_URI} !index.php来防止这种情况。