[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

HTACCESS - ModRewrite - dynamic linking?

Here's what I'm trying to accomplish.

lets say a user goes to example.com/this/that

if the directories 'this' and 'that' don't exist, I was the user to be pointed to
whatever.php?cat=this&product=that

But this shouldn't cause users to be unable to access other directories that do exist..

Categories and Products are dynamic in the database, so writing rules for each specific combination would be insane.

How do I do this?
0
trickyidiot
Asked:
trickyidiot
  • 5
  • 2
1 Solution
 
siva_sivaCommented:
Here is the rule
<rule>
      <from>([^\?]*)/([^\?]*)</from>
      <to>whatever.php?cat=$1&product=$2</to>
</rule>
0
 
trickyidiotAuthor Commented:
Will that work in a .htaccess file?
0
 
trickyidiotAuthor Commented:
This is creating an Internal Server Error

How does this translate into an htaccess file?

anyone?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
trickyidiotAuthor Commented:
Ok - I got this far:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /products.php?category=$1&product=$2 [L]

And it works, but it's causing the CSS not to parse... wtf?
0
 
siva_sivaCommented:
In my site also i am using the same rewrite rule. But i got all things right.
0
 
trickyidiotAuthor Commented:
I got it:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-[:space:]_]+)/([a-zA-Z0-9-[:space:]_]+)/?$ categories.html?category=$1&product=$2 [L]
RewriteRule ^([a-zA-Z0-9-[:space:]_]+)/?$ categories.html?category=$1 [L]
0
 
trickyidiotAuthor Commented:
I solved this issue myself and want to close the question so I'm giving you the points
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now