Wordpress htaccess重写规则的url参数。

问题描述 投票:0回答:1

我在服务器的根目录下有一个php脚本,大家是这样链接到它的。

http://mywebsite.com/test.php?id=123

我为一个客户创建了一个新的WordPress网站 并创建了一个自定义的帖子类型,接受url参数 并在访问时与旧的脚本相似。

http://mywebsite.com/test/?id=123

还要求用户总是被重定向到http,即使他来自https链接。我已经在WordPress的htaccess规则之后添加了我的重写规则。这是我的规则。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} test.php [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ test.php?id=$1 [L,QSA]
</IfModule>

第一条是总是重定向到http,第二条是重写并保留参数。 部分工作,如果我访问:

https://mywebsite.com/test.php?id=123

它会带我到:

http://mywebsite.com/test/?id=123

但如果我访问,就不会重写。

http://mywebsite.com/test.php?id=123

我缺少什么?

wordpress .htaccess mod-rewrite
1个回答
0
投票

这符合要求,它也处理www或不。在.htaccess的最后工作,所以它不冲突Wordpress规则。

RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com$
RewriteRule ^test\.php$ "http\:\/\/mywebsite\.com\/test\/" [R=301,L]
© www.soinside.com 2019 - 2024. All rights reserved.