I want to change an old database website that is not made in WordPress to WordPress. My site uses PHP variables so the URL is originally:
example/index.php?tl=1&pg=2&bs=3&hcbs=4&sc1bs=5&sc2bs=6&sc3bs=7&hc=8&blbs=9
But I could rewrite that to a normal looking URL:
example/1/2/3/4/5/6/7/8/9.php
To do that in the old site I used the following rewrite rules in the .htaccess
file:
RewriteEngine on
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$1&pg=$2&bs=$3&hcbs=$4&sc1bs=$5&sc2bs=$6&sc3bs=$7&hc=$8&blbs=$9 [L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$1&pg=$2&bs=$3&hcbs=$4&sc1bs=$5&sc2bs=$6&hc=$7&sc3bs=$8 [L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$1&pg=$2&bs=$3&hcbs=$4&sc1bs=$5&hc=$6&sc2bs=$7 [L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$1&pg=$2&bs=$3&hcbs=$4&hc=$5&sc1bs=$6 [L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$1&pg=$2&bs=$3&hc=$4&hcbs=$5 [L]
RewriteRule ^(.*)/(.*)/(.*).php ?tl=$1&pg=$2&bs=$3 [L]
But now I am trying to do so in WordPress. WordPress already has some preinstalled rewrite rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
But when I try to combine the both in any way the complete WordPress site stops working. Does anyone have an idea how to solve this?
I want to change an old database website that is not made in WordPress to WordPress. My site uses PHP variables so the URL is originally:
example/index.php?tl=1&pg=2&bs=3&hcbs=4&sc1bs=5&sc2bs=6&sc3bs=7&hc=8&blbs=9
But I could rewrite that to a normal looking URL:
example/1/2/3/4/5/6/7/8/9.php
To do that in the old site I used the following rewrite rules in the .htaccess
file:
RewriteEngine on
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$1&pg=$2&bs=$3&hcbs=$4&sc1bs=$5&sc2bs=$6&sc3bs=$7&hc=$8&blbs=$9 [L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$1&pg=$2&bs=$3&hcbs=$4&sc1bs=$5&sc2bs=$6&hc=$7&sc3bs=$8 [L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$1&pg=$2&bs=$3&hcbs=$4&sc1bs=$5&hc=$6&sc2bs=$7 [L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$1&pg=$2&bs=$3&hcbs=$4&hc=$5&sc1bs=$6 [L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$1&pg=$2&bs=$3&hc=$4&hcbs=$5 [L]
RewriteRule ^(.*)/(.*)/(.*).php ?tl=$1&pg=$2&bs=$3 [L]
But now I am trying to do so in WordPress. WordPress already has some preinstalled rewrite rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
But when I try to combine the both in any way the complete WordPress site stops working. Does anyone have an idea how to solve this?
Share Improve this question edited Apr 9, 2020 at 8:32 MrWhite 3,8911 gold badge20 silver badges23 bronze badges asked Apr 9, 2020 at 6:27 Hanno KHanno K 112 bronze badges 3 |1 Answer
Reset to default 1Here is an example of adding custom rewrite rule to WordPress.
For instance, you have a link
http://website/1/
that would like WordPress interprets internally as
http://website?tl=1
But for tl
you have mentioned, I am not sure what is your settings. So I assume tl
is working in your system. Because WP default parameter is p
for page id
You may try to use the following filter in your theme functions.php or plugin
- The following only works if permalinks is turned on. Otherwise, no effect.
It means in
settings -> permalinks
, if you choosePlain
, then WordPress will show the query without pretty URL. It is regarded asturned off
. Otherwise, if you choose other options likePost Name
then WordPress will accept Post Name as URL such ashttps://examples/sample-post/
So, if it is being enabled(or turned on). Then the the rewrite system will be used. And the following filter works with WordPress rewrite system.
Sometimes we use some other synonym
like Enable permalinks
, Disable permalinks
. It also means the same things.
Here, assume to place in functions.php
add_action( 'init', 'q363603_add_custom_rewrites' );
function q363603_add_custom_rewrites() {
// take numbers to the query tl=numbers
add_rewrite_rule('([0-9])+/?$', 'index.php?tl=$matches[1]', 'top');
}
add_filter('query_vars', 'q363603_add_custom_queryvars' );
function q363603_add_custom_queryvars( $qvars ) {
// ask WordPress to allow this query parameter
$qvars[] = 'tl';
return $qvars;
}
edited: add permalinks turning on/off explanation
tl
parameter for. If you are suretl
is working then I think the examples works for you. – 西門 正 Code Guy - JingCodeGuy Commented Apr 9, 2020 at 8:11