• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 178
  • 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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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