![]() |
|
| Domain Name Sales | Domain Software | Calculate UK Domain Drop Dates | Domain Registration | NameDrive | Domain Parking | Subscribe to our Domains For Sale newsletter |
| | ||||||
| Home | Register | Rules | Membership Upgrade | Domains For Sale | Domain Name Escrow | Mark Forums Read | Domain Classified | Chat Room |
| Website Design Discuss web design |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) |
![]() | 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 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
__________________ 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. |
| |
| | #2 (permalink) |
![]() |
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: |
| |
| | #3 (permalink) |
![]() |
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¶meter2=2¶meter3=3 /1/2/ -> page.php?parameter1=1¶meter2=2 /1/ -> page.php?parameter1=1 I'll have a look this as would be really useful |
| |
| | #4 (permalink) |
![]() |
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: |
| |
| | #5 (permalink) |
![]() |
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: |
| |
| | #6 (permalink) |
![]() |
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 |
| |
| | #7 (permalink) |
![]() |
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. |
| |
| | #8 (permalink) |
![]() |
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 |
| |
| | #9 (permalink) |
![]() |
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: |
| |
| | #10 (permalink) |
![]() |
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 |
| |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
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 |