sblake161189 Posted February 24, 2011 Share Posted February 24, 2011 Hi Guys, I no its only a partial PHP question but its still related to PHP... I have a URL .com/sites/0.php?Ter=144 and it takes you to a page and loads details with the id (ter) equalling 144 and displays all of 144's information... normal PHP stuff However I want to be able to put a Rewrite rule using a .htaccess (unless there is a better method!?) to get search engine frienly results. However I dont want the user to type .com/144 to bring up the Leeds branch. I want them to type .com/leeds and it bring up 144 (Leeds Branch). BranchName is the field I use for the branch name in my MySQL table. Is this possible? Also when I enter .com/sites/0.php?BranchName=Leeds that doesnt work either... Cheers, Sam Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted February 24, 2011 Share Posted February 24, 2011 Get the PHP working first. The problem is that on 0.php you are querying for Ter, something like: WHERE id = $_GET['Ter'] But you need to query on BranchName, something like: WHERE branch_name = $_GET['BranchName'] Quote Link to comment Share on other sites More sharing options...
sblake161189 Posted February 24, 2011 Author Share Posted February 24, 2011 Thanks for that My PHP script at the top of my page (0.php) is as follows: <?php include('../admin/config.php'); if (isset($_GET['Ter']) ) { $ter = (int) $_GET['Ter']; $row = mysql_fetch_array ( mysql_query("SELECT * FROM `ter` WHERE `Ter` = '$ter' ")); ?> Can I say in PHP: SELECT * FROM `ter` WHERE `Ter` = '$ter' or `BranchName` = '$branchname' Does that make sense? Cheers Quote Link to comment Share on other sites More sharing options...
sblake161189 Posted February 24, 2011 Author Share Posted February 24, 2011 Ignore my last post... I have now changed it so it works off BranchName <?php include('../admin/config.php'); if (isset($_GET['BranchName'])) { $ter = (int) $_GET['Ter']; $branchname = $_GET['BranchName']; $row = mysql_fetch_array ( mysql_query("SELECT * FROM `ter` WHERE `BranchName` = '$branchname' ")); ?> So any clues on how to modify the .htaccess so the user can type .com/leeds and it takes you to .com/sites/0.php?BranchName=Leeds but remains as .com/leeds in the address bar? Thanks, Sam Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted February 24, 2011 Share Posted February 24, 2011 This isn't very flexible because everything will be considered a branch name which is probably not all your site does or will do (not tested, but something like): RewriteRule ^(.*)$ /sites/0.php?BranchName=$1 [L] It would be better to do something like: RewriteRule ^BranchName/(.*)$ /sites/0.php?BranchName=$1 [L] Quote Link to comment Share on other sites More sharing options...
sblake161189 Posted February 24, 2011 Author Share Posted February 24, 2011 Cheers fella, That kind of on the right lines of what I'm looking far so thanks RewriteRule ^BranchName/(.*)$ /sites/0.php?BranchName=$1 [L] But that means I have to type .com/BranchName/leeds for it come up Any way of modifying it so its just .com/leeds Cheers I have also just tried RewriteRule ^(.*)$ /sites/0.php?BranchName=$1 [L] and I got a 404 error for .com/leeds hmmmm Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted February 24, 2011 Share Posted February 24, 2011 Cheers fella, That kind of on the right lines of what I'm looking far so thanks RewriteRule ^BranchName/(.*)$ /sites/0.php?BranchName=$1 [L] But that means I have to type .com/BranchName/leeds for it come up Any way of modifying it so its just .com/leeds Cheers Yes, the first example, but like I said, if your site also has other functionality other than just displaing branches, like mortgages.php or something, then the first rule will rewrite it into: /sites/0.php?BranchName=mortgages.php So it is most likely problematic. Quote Link to comment Share on other sites More sharing options...
sblake161189 Posted February 24, 2011 Author Share Posted February 24, 2011 I have also just tried RewriteRule ^(.*)$ /sites/0.php?BranchName=$1 [L] and I got a 404 error for .com/leeds hmmmm Quote Link to comment Share on other sites More sharing options...
sblake161189 Posted February 24, 2011 Author Share Posted February 24, 2011 Sorted Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ /sites/0.php?BranchName=$1 [QSA] Yet again, thanks again for your help! Quote Link to comment 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.