0
votes

I have a php script on the root of the server that people link to it like this:

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

I have created a new WordPress website for a client and created a custom post type that accepts url parameters and works similarly to the old script when accessed at:

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

It is also requested that user is always redirected to http, even if he comes from a https link. I've added my rewrite rules after WordPress rules in htaccess. These are my rules:

<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>

First one is to always redirect to http and second to rewrite and retain parameter. It partially works, if I access:

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

it takes me to:

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

but no rewrite if I access:

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

What am I missing?

1

1 Answers

0
votes

This meets requirements, it also handles www or not. Works at the end of .htaccess so it doesn't conflict Wordpress rules:

RewriteCond %{HTTP_HOST} ^mywebsite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mywebsite\.com$
RewriteRule ^test\.php$ "http\:\/\/mywebsite\.com\/test\/" [R=301,L]