Jump to content

Gotta be a better way...


The14thGOD

Recommended Posts

I've tried several different ways to get something similar to work but none of them came out successful.

basically i have this:

RewriteEngine On
RewriteRule ^products/([a-z0-9-]+) page.php?theurl=$1 [L]
RewriteRule ^solutions/([a-z0-9-]+) page.php?theurl=$1 [L]
RewriteRule ^services/([a-z0-9-]+) page.php?theurl=$1 [L]
RewriteRule ^news/([a-z0-9-]+) page.php?theurl=$1 [L]
RewriteRule ^company/([a-z0-9-]+) page.php?theurl=$1 [L]
RewriteRule ^lab/([a-z0-9-]+) page.php?theurl=$1 [L]
RewriteRule ^contact/([a-z0-9-]+) page.php?theurl=$1 [L]

RewriteRule ^products/([a-z0-9-]+)/([a-z0-9-]+) page.php?theurl=$1/$2 [L]
RewriteRule ^solutions/([a-z0-9-]+)/([a-z0-9-]+) page.php?theurl=$1/$2 [L]
RewriteRule ^services/([a-z0-9-]+)/([a-z0-9-]+) page.php?theurl=$1/$2 [L]
RewriteRule ^news/([a-z0-9-]+)/([a-z0-9-]+) page.php?theurl=$1/$2 [L]
RewriteRule ^company/([a-z0-9-]+)/([a-z0-9-]+) page.php?theurl=$1/$2 [L]
RewriteRule ^lab/([a-z0-9-]+)/([a-z0-9-]+) page.php?theurl=$1/$2 [L]
RewriteRule ^contact/([a-z0-9-]+)/([a-z0-9-]+) page.php?theurl=$1/$2 [L]

 

and want to transform it into something smaller like:

RewriteEngine On
RewriteRule ^(products)|(solutions)|(services)|(news)|(company)|(lab)|(contact)/([a-z0-9-]+) page.php?theurl=$2 [L]
RewriteRule ^(products)|(solutions)|(services)|(news)|(company)|(lab)|(contact)/([a-z0-9-]+)/([a-z0-9-]+) page.php?theurl=$2/$3 [L]

 

I think the above got me to the closet working but it was breaking css or something (its not broken at all with the top one so it shoudln't be a path or anything like that issue).

 

Can anyone help a mod_rewrite newb out?

it would be even better if i could get it on one line but i'm not sure if thats possible due to the database and what it's getting, the extra / in the url would have to be optional/only put if there is a 3rd argument.

Thanks!,

Justin

Link to comment
https://forums.phpfreaks.com/topic/172028-gotta-be-a-better-way/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.