Category Archives: add

WordPress rewrite dynamic url

I want to expand my Wordpress site with lots of products per category dynamically. I have a category with url example.com/koelkast page where I retrieve all products from my database with:

<?php
global $wpdb;
$databasetabel =  get_post_meta( $post_id, 'database-prefix', true);

$data = $wpdb->get_results("
SELECT *
FROM  $databasetabel  
LIMIT 0, 100;
");

foreach ($data as $info) {
echo '<a href=wp-content/themes/mytheme/tpl_detailpagina.php?cat='.$databasetabel.'&idnummer='.$info->idnummer.'>'.$info->typenummer.'<br>';
    }   
} else
{ 
?>

This works and I get a nice list of all category products. When I click on a link, the detail page has the following url:

https://www.example.com/wp-content/themes/mytheme/tpl_detailpagina.php?cat=koelkast&idnummer=76

And I use $_GET to receive the right detail information.

But I want it to be for example: example.com/koelkast/miele-w3203 where miele-w3203 is the productname.

I've checked lots of tutorials, but I can't get it to work? Do I need to use Wordpress add_query_vars or just rewrite it with my .htaccess file? What is the best approach here?

How can I add conditional url variable using htaccess?

I use following code:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{QUERY_STRING} (^|&)post_type=product(&|$)
RewriteCond %{QUERY_STRING} !(^|&)product_cat=xyz
RewriteRule ^(.*)$ http://www.example.com/?%{QUERY_STRING}&product_cat=xyz

but it doesn't works.

I need to add variable "product_cat=xyz" where query_string contains "post_type=product" and it doesn't just contains "product_cat=xyz".

Examples: If url is "http://www.example.com/?post_type=product&product_cat=xyz" then htacces leaves it unchanged.

If url is "http://www.example.com/?post_type=product" then htacces must add "&product_cat=xyz"

:-) Can you help me, please? Thanks in advance.

Add text to beggining of URL with .htaccess

Good morning to everyone. I am trying to force rewrite all petitions ($URL) that don't come from adf.ly to http://www.adf.ly/436787/$URL through the .htacces file, so this is how it looks like at the moment:

<IfModule mod_rewrite.c>
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} !^adf\.ly\.436787.\$ [NC]
  RewriteRule ^ http://www.adf.ly/436787/%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

The problem is that ALL the petitions are reconverted, including those ones that come from adf.ly. Demo. Please, help me to find the error.

Any help will be appreciated. Thank you for dedicating your time to my stupid questions.

*I'm not native English. Expect gramatical, syntax and ortographical errors. If you detect them, please, notify me.