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 page where I retrieve all products from my database with:

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

$data = $wpdb->get_results("
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:

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

But I want it to be for example: 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 ^(.*)${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 "" then htacces leaves it unchanged.

If url is "" 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 to$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_HOST}%{REQUEST_URI} [R=301,L]

The problem is that ALL the petitions are reconverted, including those ones that come from 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.