我想通过function.php将域重定向到“.htaccess”
如果我想根据每条规则重定向下面的域,我应该如何编写.htaccess文件?
"ex.com/function.php"
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(比如3个字符到"tt“参数)
所有的目的都是因为function.php中需要参数。
<?php
$type = $_GET['tt'];
$num = $_GET['num'];
$fo = $_GET['fo'];
if(!empty($fo)){
$fo = "n";
}
....-新问题
如果我有两个域,并且只有子域"ex.com“需要工作,我应该这样写吗?只有主域具有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>发布于 2021-12-01 01:42:46
您可以在您的.htaccess或Apache中使用它:
RewriteEngine on
RewriteRule ^/?([0-9A-Za-z]{3})([0-9]+)$ /function.php?tt=$1&num=$2 [QSA,L]其中:
^/?路径以一个可选的slash([0-9A-Za-z]{3})开始--捕获括号中将成为$1([0-9]+)的三个数字或字母--捕获将成为$2$的括号中的一个或多个数字--匹配URL pathQSA的末尾--“查询字符串追加”,它将保留查询stringL中已经存在的其他参数--“path”,这将阻止其他重写规则在匹配时运行。
此规则不会重定向和更改URL。如果希望用户被重定向,可以将R=301添加到逗号分隔的标志列表中,即。[QSA,L,R=301]
https://stackoverflow.com/questions/70177560
复制相似问题