drjnet Posted January 12, 2010 Share Posted January 12, 2010 Hi, Im struggling with this, any help would be much appreciated. I have a site with two types of pages like this Categories - http://www.domain.com/listing.php?brandid=14 Products - http://www.domain.com/details.php?prodid=297 I need to move to this: Categories - http://www.domain.com/category-alias Products - http://www.domain.com/product-alias For various reasons it will be easier for me to add another parameter to the urls rather than simple replace the id with the aliases, so i will be able to get to this Categories - http://www.domain.com/listing.php?brandid=14&alias=category-alias Products - http://www.domain.com/details.php?prodid=297&alias=product-alias My questions are : a) Can i setup a rewrite rule that ignores everything upto the alias (as the id will vary) and just picks up the alias so my urls look like this Categories - http://www.domain.com/category-alias Products - http://www.domain.com/product-alias I've got this so far in my .htaccess: RewriteEngine on RewriteRule ^([A-Za-z0-9-]+)/?$ listing.php?brandid=$1&alias=$2 [L] RewriteRule ^([A-Za-z0-9-]+)/?$ details.php?prodid=$1&alias=$2 [L] But if i stick this in the browser for example : http://www.domain.com/listing.php?brandid=15&alias=test-alias the url does not rewrite/redirect to: http://www.domain.com/test-alias Am I missing something really simple? htaccess is definately work ok just not my rewrite rules. Can anyone help ? thanks Quote Link to comment https://forums.phpfreaks.com/topic/188223-rewrite-help-how-to-ignore-first-query-string-parameter/ Share on other sites More sharing options...
cags Posted January 14, 2010 Share Posted January 14, 2010 In my opinion you seem to be looking at the problem entirely backwards (which seems very common with mod_rewrite). You don't really want to type that URL (the one with the query string) into the address bar and have the other (the 'neat' URL) appear, you want people/sites to use the 'neat' URL and have the one with a query string be the one that the user sees (but without the address bar changing). If you wish to use the id, there is no escaping it will have to be in the URL, generally speaking people would use domain.com/id-number/title. That way the number is there for the background work, but the title is still visible. Quote Link to comment https://forums.phpfreaks.com/topic/188223-rewrite-help-how-to-ignore-first-query-string-parameter/#findComment-995017 Share on other sites More sharing options...
drjnet Posted January 14, 2010 Author Share Posted January 14, 2010 You are dead right, i was informed about this today and fell fairly stupid!!! (no actually very stupid...) I guess what i need to know then is how to send my short urls through some kind of script using htaccess to use mod_rewrite effectively. Now its been pointed out, it clear i was looking at this arse backwards (no change there). Anyone got any pointers? Im guessing i need to tell htaccess to push all urls matching a certain regex through some kind of helper script that points the request at the full url? So it looks like i just need to modify the ugly url so it will work and carry the appropriate info (e.g. nice title) then setup some rewrite rules?? Quote Link to comment https://forums.phpfreaks.com/topic/188223-rewrite-help-how-to-ignore-first-query-string-parameter/#findComment-995105 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.