Forum Moderators: phranque
RewriteRule (.*)-store/id/([^/]+)$ http://www.example.com/$1-promo-code-discount-coupons-codes/id/$2/ [R=301,L]
RewriteRule store/id/(.*)/ maincode.php?id=$1
The resulting url is : http://www.example.com/theshop-store/id/542125877451369/
In the resulting url above :
1> theshop - is the name of the shop taken from the database
2> 542125877451369 - is the id of the the shop take from the database
3> -store - is just an additional word in the url (static in all urls)
Now the problem is that anything after the "/" also give the same result.
For eg:
http://www.example.com/theshop-store/id/542125877451369/dfsfs
http://www.example.com/theshop-store/id/542125877451369/%22
How do i redirect these to http://www.example.com/theshop-store/id/542125877451369/
What i want is that whatever happens, when anyone types anything after the last "/" should be redirected to the ending "/".
Please help!
[edited by: jdMorgan at 12:42 pm (utc) on Oct. 9, 2008]
[edit reason] Please use example.com [/edit]
[0-9]{15} because it will stop any and all requests with letters in, and will stop any requests that are too long or too short from even hitting the scripts. One question. Is the /id/ bit static? If it is, then it does not need to appear in the URL. The fact that there is a 15-digit number there is enough to separate out that it is an id and the rule can key off that, as above.
Add something like this before your "store" first rule:
RewriteRule ^([^-]+)-store/id/([0-9]{15})/. http://www.example.com/$1-store/id/$2/ [R=301,L]
This assumes that no store name will have a hyphen in it. To handle store names with hyphens, you'd need the more-complex and slower-to-process rule:
RewriteRule ^(([^-]+-)+)store/id/([0-9]{15})/. http://www.example.com/$1store/id/$3/ [R=301,L]
Jim
Sorry for not being very clear about the store-id and store name. I am sending below the exact version of the script and details of the url variables. Please ignore the earlier ones above.
RewriteRule (.*)-online-store-promotion/store-id/([^/]+)$ http://www.example.com/$1-promo-code-discount-coupons-codes/store-id/$2/ [R=301,L]
RewriteRule online-store-promotion/store-id/(.*)/ promo-code-discount-coupons-codes.php?store-id=$1
Url generated : http://www.example.com/Flowers-online-store-promotion/store-id/542125877451369/
Details:
1> The store-id value 542125877451369 here is not fixed. It can be 6 digits or even 15 digits (any value) and its taken from the database.
2> Flowers is the name of one of the stores that has the store-id value 542125877451369 and is also taken from the database.
3> Here the store name is Flowers but it can also be Flow-ers or even Fl123-wrs (can contain hypen)
4> promo-code-discount-coupons-codes.php file takes in the store-id as input.
5> -online-store-promotion is just a made up text in the url that is static for all the urls generated.
6> I cannot change the url format above as its already in the search engines.
My only problem is that when anyone types anything after the last "/" should be redirected to the ending "/".
Please help.
[edited by: jdMorgan at 4:28 pm (utc) on Oct. 9, 2008]
[edit reason] Please use example.com only. [/edit]
RewriteRule ^(([^-]+-)+)online-store-promotion/store-id/([0-9]{6,15})/. http://www.example.com/$1online-store-promotion/store-id/$3/ [R=301,L]
RewriteRule ^([^-]+-)+online-store-promotion/store-id/([0-9]{6,15})/ promo-code-discount-coupons-codes.php?store-id=$2 [L]
You will note that in the Apache URL Rewriting Guide at apache.org, the ".*" pattern is almost never used.
Completely flush your browser cache before testing new code.
Jim
Shame. Maybe from here on in, you could stick with a fixed format, with a fixed number of digits for all new store IDs?
I am a regular user of fixed-length data wherever and whenever I can - padding with leading zeroes, whatever it takes.
g1smd : i have learnt from my mistake.....
jim : the code worked like magic. but now the new problem is that when i type the url without the ending slash it does not redirect.
What i mean is as follows :
http://www.example.com/Flowers-online-store-promotion/store-id/542125877451369 - shows no page found, it should actually redirect to http://www.example.com/Flowers-online-store-promotion/store-id/542125877451369/
> your store-id can range from 6 to 15 digits - its actaully not fixed to any number, the range can be from 1 to just about anything, still i have changed the range to {2,30} for safety, is there a better way ?
thanks a ton.