0

I would like to rewrite the following URL string from:

product.php?category=abstract_and_patterns&page=1

To:

abstract-and-patterns

Now it's important to note that both the category and page variables will always be different depending on what page the user is on or which category they have selected.

I have spent hours trying to figure this out with no success.

[EDIT]

I've tried a ton of things but the latest rewrite I've tried works but comes up with a 404 error.

RewriteCond %{QUERY_STRING} ^category=([^&]+)&page=([^&]+)$
RewriteRule ^product.php$ /%1/%2? [L,R=301]

[EDIT]

Just so you guys know, there is actually only 1 page, that is the products.php page. The information on that page is pulled from the database based on the values in the query string. Now obviously for both user friendliness and also SEO purposes I need the URLs to be clean rather than category=abstrsct_and_patterns&page=3 but I also need the query strings to be remembered, especially for pages, so that the site still functions. Is this even possible? Thanks.

Gareth Daine
  • 4,016
  • 5
  • 40
  • 67
  • Perhaps you could show us what you've tried? – scottlimmer Oct 29 '12 at 09:57
  • Am I right in thinking that if I get the above rewrite to work that there would have to be a page located at whatever category name it has been rewritten to? – Gareth Daine Oct 29 '12 at 10:01
  • I think you're thinking about it backwards. You want to match on abstract-and-patterns and convert that to ?category=abstract-and-patterns – scottlimmer Oct 29 '12 at 12:33
  • Thanks for commenting but I am after doing it backwards. Because of the way the database has been structured I've had to dynamically generate the content based on values in the query string, meaning that no actual separate pages exist, just product.php. Then based on the values in the query string the content is pulled from the database. So, when the user requests the URL product.php?category=absract_and_patterns&page=3 I need to rewrite that URL to /abstract_and_patterns/page-3 or something similar. That's why I needed to know if it was possible. – Gareth Daine Oct 29 '12 at 12:37
  • It's also worth noting that I will still need the query string values to be available for use within my PHP code otherwise it won't work. – Gareth Daine Oct 29 '12 at 12:39
  • I'm not in a position to test at the moment, but I think you want something like (comment out the RewriteCond also): RewriteRule product.php?category=([a-zA-Z0-9-_]+])&page=([0-9]+) /$1/page-$2 – scottlimmer Oct 29 '12 at 12:43

1 Answers1

0

Turns out that this cannot be achieved the way I wanted it to be.

Gareth Daine
  • 4,016
  • 5
  • 40
  • 67