Buy Sell Discuss UK Domain Names at AcornDomains.co.uk Free Virtual Servers

Today's Drop Dates are: 19-02-2012 or 26-02-2012   All times are GMT. The time now is 01:41:04 PM.
Domain Name Sales Domain Software Calculate UK Domain Drop Dates Domain Registration NameDrive Domain Parking Subscribe to our Domains For Sale newsletter
Go Back   Domain Forum Acorn Domains Buy Sell Auction UK Domains > Website Design and Promotion > Website Design
Connect with Facebook

Website Design Discuss web design

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 16-11-2009, 12:50:12 PM     #1 (permalink)

 
Join Date: May 2007
Posts: 1,148
monaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond repute

Any .htaccess rewrite gurus

I'm wanting to do a conditional rewrite with differing numbers of parameters some optional.

Is this possible

Code:
www.domain.co.uk/search/butcher/town/mytown
www.domain.co.uk/search/butcher/county/mycounty/page7
www.domain.co.uk/show/123
this would need to go into index.php as

Code:
index.php?function=search&category=butcher&town=mytown
index.php?function=search&category=butcher&county=mycounty&page=7
index.php?function=show&key=123
The page value is optional
__________________
Alex Monaghan - Drop Catch & Drop Lists - PM for details
Online Accounting|Pine Furniture|Barbie

Last edited by monaghan; 16-11-2009 at 12:52:24 PM.
monaghan is offline  
Old 16-11-2009, 02:20:53 PM     #2 (permalink)

 
Skinner's Avatar
 
Join Date: Jul 2008
Location: Manchester
Posts: 2,507
Skinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond repute

I can't think of an easy way but this is way into RegEx not so much htaccess.

You would need your index to use a switch statement on the function element, I expect from there the htaccess wouldn't be too hard.

I'll have another look after I get back home, I'm about to head out in 30 minutes or so.

If your familiar with basic rewrites once you break up the function switches the rest should be simple.
__________________
Browse:
Skinner is offline  
Old 16-11-2009, 02:41:37 PM     #3 (permalink)

 
Nick's Avatar
 
Join Date: Apr 2008
Posts: 730
Nick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond repute

I'm interested too

Basically a way to pass 'x' parameters based on number of 'x' folders

Looked into this previously but couldn't find an answer

I ended up having to hardcode all alternative number of parameters

/1/2/3/ -> page.php?parameter1=1&parameter2=2&parameter3=3
/1/2/ -> page.php?parameter1=1&parameter2=2
/1/ -> page.php?parameter1=1

I'll have a look this as would be really useful
Nick is offline  
Old 16-11-2009, 02:52:24 PM     #4 (permalink)

 
Skinner's Avatar
 
Join Date: Jul 2008
Location: Manchester
Posts: 2,507
Skinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond repute

Maybe something like

RewriteRule ^/(.*)/?(.*)/town/?(.*) index.php?function=$1&category=$2&town=$3

I haven't checked this but it may give you a starting point.
__________________
Browse:
Skinner is offline  
Old 16-11-2009, 02:53:58 PM     #5 (permalink)

 
Skinner's Avatar
 
Join Date: Jul 2008
Location: Manchester
Posts: 2,507
Skinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond repute

Would need to pass a blank variable for optionals like page= then use the PHP to disregard the option, with an if $_post['page'] == "" then $page=0 kinda deal.
__________________
Browse:
Skinner is offline  
Old 16-11-2009, 03:16:59 PM     #6 (permalink)

 
Nick's Avatar
 
Join Date: Apr 2008
Posts: 730
Nick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond reputeNick has a reputation beyond repute

This looks best I've found

Code:
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.+)/([^/]+)/([^/]+)$ $1?$2=$3 [QSA,E=TEST:$1]

RewriteCond %{ENV:TEST} ^(.+)/([^/]+)/([^/]+)$
RewriteRule ^.*$ %1?%2=%3 [QSA,E=TEST:%1,N]

RewriteCond %{ENV:TEST} ^([^/]+)/(.+)$ [OR]
RewriteCond %{REQUEST_URI} ^/([^/]+)/(.+)$
RewriteRule ^.*$ test.php?%1=%2 [QSA,L]

MOD REWRITE Guide & Common Requests - Dev Shed

GL
Nick is offline  
Old 16-11-2009, 11:30:49 PM     #7 (permalink)

 
Skinner's Avatar
 
Join Date: Jul 2008
Location: Manchester
Posts: 2,507
Skinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond repute

Nick, yours is easy

RewriteEngine on
RewriteRule ^(.*)/(.*)/(.*) sample.php?var1=$1&var2=$2&var3=$3

That will call the sample.php document and populate var1-3 with the folder names.

Try it with

<?php
echo "1 = " . $_GET['var1'] . "<br>";
echo "2 = " . $_GET['var2'] . "<br>";
echo "3 = " . $_GET['var3'] . "<br>";
?>

in the sample.php file.

The other one is complex due to not using the same function, you could write mod_rw for each function but it would be a killer regex to do it in one go.
__________________
Browse:

Last edited by Skinner; 17-11-2009 at 02:27:43 AM.
Skinner is offline  
Old 17-11-2009, 10:42:02 AM     #8 (permalink)

 
Join Date: May 2007
Posts: 1,148
monaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond repute

Thanks for the replies

Using

RewriteEngine on
RewriteRule ^(.*)/(.*)/(.*) sample.php?var1=$1&var2=$2&var3=$3

could this cope with variable number of parameters or would I need a rule for each number of parameters? Handling in the PHP code is quite simple as the function would define the number of parameters I'm expecting and my code alread reads the input and sanitises it before assigning to local variable / SQL query string.
__________________
Alex Monaghan - Drop Catch & Drop Lists - PM for details
Online Accounting|Pine Furniture|Barbie
monaghan is offline  
Old 17-11-2009, 12:49:38 PM     #9 (permalink)

 
Skinner's Avatar
 
Join Date: Jul 2008
Location: Manchester
Posts: 2,507
Skinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond repute

I guess as long as your URLs was contructed the same way everytime...

You would just need to sort it out in php.

You would need to pass it ALL the possible variables, so if there was 7 possibles you would need to pass it all 7 every time, then use php to test the content of the variable.

Because, Town, Country, Search, Show all seem to be static variables, you could write 1 rule for each 'type' and simply check for the type.

case 'search':
$var1 = blah
etc

case 'show':
etc

Then you could disregard the exess fragments there.

The important bit is that your URL structure never changes otherwise the variables would too.
__________________
Browse:
Skinner is offline  
Old 17-11-2009, 01:26:39 PM     #10 (permalink)

 
Join Date: May 2007
Posts: 1,148
monaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond reputemonaghan has a reputation beyond repute

I was thinking more of the regex rather than the PHP, I'll know from function what expect, but the URL will have differing number of parameters and my limited regex knowledge would suggest that sample above is working with just 3 parameters and would fail if just 2.

I guess I'll need to devote an hour or so to "fiddle time" and see what I can make it do.
__________________
Alex Monaghan - Drop Catch & Drop Lists - PM for details
Online Accounting|Pine Furniture|Barbie
monaghan is offline  
Closed Thread



Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Domain Name Community Replies Last Post
.htaccess help SecNam Website Design 1 07-09-2009 01:42:31 AM
URL Rewrite GeoMal Services Wanted 2 06-02-2009 09:20:25 AM
Mod Rewrite assistance grantw Search Engine Optimisation 5 23-12-2007 10:08:43 AM
mod rewrite anyone? SecNam Search Engine Optimisation 6 03-08-2007 01:35:03 PM
catch all with .htaccess stevie General Board 4 05-10-2006 10:19:43 PM


All times are GMT. The time now is 01:41:04 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.0 RC 2
All content on Acorn Domains is member generated and is not moderated before posting. All content is viewed and used by you at your own risk and AD does not warrant the accuracy or reliability of any of the information. The views expressed are those of the individual contributors and not necessarily those of AD. Please contact us to report any issues or send a PM to "Admin".