Cory Nickerson
Cory Nickerson

Reputation: 913

SEO Friendly URLs .htaccess

I'm working on the .htaccess file for creating SEO Friendly Urls. Still experimenting with it and it works good so far. I was looking to make it a bit more dynamic.

I want the URL structures to be similar to what is below, but I don't always know how many levels there will be.

http://website.com/level_1/level_2/level_3/level_4/

In the .htaccess file below I manually coded it to detect 2 levels of the URL. Is there a way I can make it check the last level and then work back from there to make it easier? So In other words if the URL had 3 levels it would detect that and then the RewriteRule would adjust to how many levels there are.

RewriteEngine On

RewriteRule ^([a-zA-Z0-9-/]+)/$([a-zA-Z0-9-/]+)/$ index.php?a=$1&b=$2
RewriteRule ^([a-zA-Z0-9-/]+)/$([a-zA-Z0-9-/]+)$ index.php?a=$1&b=$2
RewriteRule ^([a-zA-Z0-9-/]+)/$ index.php?a=$1
RewriteRule ^([a-zA-Z0-9-/]+)$ index.php?a=$1

Upvotes: 0

Views: 1200

Answers (1)

ceejayoz
ceejayoz

Reputation: 180177

Typically, you'd be better off doing RewriteRule ^(.*)$ index.php?path=$1 and allowing your index.php file handle the logic.

Upvotes: 2

Related Questions