【发布时间】:2022-01-07 15:39:24
【问题描述】:
我想通过 .htaccess 将域重定向到“function.php”
如果我想根据每个规则重定向下面的域,我应该如何编写.htaccess文件?
-
“ex.com”到“ex.com/function.php”
-
ex.com / {3 个字符到“tt”},{剩余数字到“num”}
tt 参数总是有 3 个字符。 num参数是随机的,可以是1,也可以是2~8。
"ex.com/3Ad32" to "ex.com/function.php?tt=3Ad&num=32"
"ex.com/5eX9901" to "ex.com/function.php?tt=5eX&num=9901"
"ex.com/5Db930" to "ex.com/function.php?tt=5Db&num=930"
3.如果域有参数,则同样重定向。
"ex.com/3Ad32?fo=test" to "ex.com/function.php?tt=3Ad&num=32&fo=test"
"ex.com/5eX9901?fo=ops" to "ex.com/function.php?tt=5eX&num=9901&fo=ops"
"ex.com/5Db930fo=thx&te=on" to "ex.com/function.php?tt=5Db&num=930&fo=thx&te=on"
我什至不知道 .htaccess 文件是否可以剪切某些 URL(例如“tt”参数中的 3 个字符)
所有目的都是因为function.php中需要参数。
<?php
$type = $_GET['tt'];
$num = $_GET['num'];
$fo = $_GET['fo'];
if(!empty($fo)){
$fo = "n";
}
....
------新问题。
如果我有两个域,并且只有子域“ex.com”需要工作,我应该这样写吗?只有 Maindomain 有 SSL。
-----current .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
到
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?main.com$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?ex.com$
RewriteRule ^/?([0-9A-Za-z]{3})([0-9]+)$ /function.php?tt=$1$num=$2 [QSA, L]
</IfModule>
【问题讨论】:
标签: php .htaccess redirect hosting