Christian
Christian

Reputation: 121

Multiple RewriteRules in htaccess to same file

Okay so I am really rookie in htaccess and everything I do is kind of trial and error.

I have to make a couple of landingpages for my website and need to control the URL’s in htaccess so they look nice for google etc.

#Landingpages ex.
RewriteRule ^colors/ article.php
RewriteRule ^sizes/ article.php
RewriteRule ^categories/ article.php

So when I enter the url www.domain.com/colors it goes to article.php where I can pick up the url with $_SERVER['REQUEST_URI'] and get ‘/colors’ to make a lookup in my DB

I will properly have 25 of these.

I also want to do /colors/green and use that as key for my db, but I don’t want to add a RewriteRule for that like below, because then I would have so many

RewriteRule ^colors/green article.php

NB: I also have other pages that I dont want to go article.php like /basket or /profile, etc.

What is the best way to do the above?

Can I make it in one RewriteRule?

Can I send the word ex. Colors as a get parameter to article.php?

Upvotes: 1

Views: 34

Answers (1)

anubhava
anubhava

Reputation: 784898

You can use regex alternation and capture group to capture a value from URI that can be passed as GET parameter:

RewriteEngine on

RewriteRule ^(colors(?:/green)?|sizes|categories)/ article.php?id=$1 [L,QSA,NC]

Upvotes: 1

Related Questions