tryingtolearn Posted April 9, 2011 Share Posted April 9, 2011 Hi all, Im working with the coffee shop ex. I cannot get the links to work that require the mod rewrite. (I have tested that mod rewrite is enabled and working by putting up a basic example on its own and it worked). I was trying to load all the files in a subdirectory, then a sub domain now I just have the files in the root and all I get in all tests is a page cannot be displayed error. I feel like Im missing something here but cant tell what it is. Is there something that needs to be changed from the download scripts - Im at a loss with this step. Thanks for any input. Link to comment Share on other sites More sharing options...
tryingtolearn Posted April 10, 2011 Author Share Posted April 10, 2011 The problem gets even stranger, Im running the coffee ex on two sites Both hosted at the same place both have the same hosting plans The first test site I get page not found errors when clicking the coffee link The second test site I get the page /shop/coffee/ and see all the items Then if I click a view all link I get the error page so its telling me its not writing something??? So am I spinning my wheels here trying to use the mod rewrite - Is it working for others? Should I just convert the links or does it sound like a different issue? Not understanding the differences between both sites on the same server? Link to comment Share on other sites More sharing options...
Jonathon Posted April 10, 2011 Share Posted April 10, 2011 Hello tryingtolearn, I am sadly not particulary brilliant with complex mod_rewrite rules. You may see I have my own .htaccess question in the forum. But for people to understand and help you with your problem, you'dneed to show the rules being used in conjunction with the urls they are meant to be working on. **Please put any code between [code]// examples of code inside code tags, close the tag using '/' just like any other html element tags as its easier to read, theres also an option in "other styles" to add code** Link to comment Share on other sites More sharing options...
tryingtolearn Posted April 10, 2011 Author Share Posted April 10, 2011 Thanks for the tip Jonathon Its just the code straight from the book(well download section for the book). <IfModule mod_rewrite.c> RewriteEngine on # For sales: RewriteRule ^shop/sales/?$ sales.php # For the primary categories: RewriteRule ^shop/([A-Za-z\+]+)/?$ shop.php?type=$1 # For specific products: RewriteRule ^browse/([A-Za-z\+\-]+)/([A-Za-z\+\-]+)/([0-9]+)$ browse.php?type=$1&category=$2&id=$3 # For HTTPS pages: RewriteCond %{HTTPS} off RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L] </IfModule> Guess a better question would be - Is producing links in this manner a reliable method? It seems hit and miss since I get totally different results between two sites hosted at the same place w/ the same hosting plan. But using straight mod rewrite like RewriteRule ^/?testrw\.html$ testrw.php [L] works fine on both sites. you could go to testrw.html and get testrw.php instead. So just wondering now if anyone has got this working out of the box, and if so - wonder what the difference is. I think for reliability sake I need to just use the dynamic urls and take the hit on the SEO unless of course Im missing something somewhere. Link to comment Share on other sites More sharing options...
Larry Posted April 11, 2011 Share Posted April 11, 2011 I couldn't even begin to provide an answer without knowing some specific details, such as the operating system in use, the directory structure, the URLs, etc. Link to comment Share on other sites More sharing options...
tryingtolearn Posted April 11, 2011 Author Share Posted April 11, 2011 Both sites Running on Linux PHP ver 5.2.14 Both are residing in the root directory now. First site that gives page cannot be displayed error My link Click Coffee Goodies Sales or any of the images Second Site My link Coffee Goodies Sales all bring up the same items but then click one of those items and you get an error page. Let me know if you need more info Link to comment Share on other sites More sharing options...
Terry Posted April 12, 2011 Share Posted April 12, 2011 Question. Do the files you are rewriting the URL to actually exist and are readable by browsers? I have not gotten that far into the book yet but today I have been doing a lot of htaccess and mod_rewrite stuff. Looking at both live examples it looks like the second example has same code as first site, have you done a line by line comparison in your editors or IDE to see what the actual differences are? To me, not know any more than what you posted and looking at the results on your sites, it seems that the actual files sales.php, and whatever you are rewriting to for coffee, goodies don't actually exist or are not readable via browser. Second Site: http://www.acmaine.com/shop/sales/ <-- WORKS http://www.acmaine.com/shop/sales.php <-- WORKS First Site: http://www.buythebead.com/shop/sales/ <-- NO WORK http://www.buythebead.com/shop/sales.php <-- NO WORK That is why I am thinking there is a file placement or permissions issue. Link to comment Share on other sites More sharing options...
Terry Posted April 12, 2011 Share Posted April 12, 2011 After looking at the htaccess code I see what is suppose to be happening and that the actual php files are not in the shop folder, if that folder exists. I am going to go back to reading the book, ignore my post above it doesn't apply to this. If both sites have same hosting and are on same exact server then I wouldn't think it is a hosting config issue. You may want to verify that the sites are on same server, sometimes sites are not even in same hosting plan within cpanel. I would rename the htaccess file on site one and copy the htaccess file from site two over and see if that works. If so then there maybe some funkiness with the htaccess file on site one, corrupted or not working due to uploaded in wrong format binary vs ascii etc... OR junk characters inserted from your editor or something. Link to comment Share on other sites More sharing options...
tryingtolearn Posted April 12, 2011 Author Share Posted April 12, 2011 Thanks Terry, I have uploaded and reuploaded so many times trying to figure it out. No luck. Even on the site where the links go to a page and display it, it isnt displaying the correct items. The goodies page should be showing the flower mug and red dragon mug. Not the same coffee products as the coffee link. Link to comment Share on other sites More sharing options...
tryingtolearn Posted April 12, 2011 Author Share Posted April 12, 2011 On the second site I started changing the urls to the dynamic ones and it seems to be working like a charm. Leads me to believe that something isnt working exactly right w/ the htaccess file or the server or a combo or USER ERROR hahaha. Link to comment Share on other sites More sharing options...
Larry Posted April 13, 2011 Share Posted April 13, 2011 Are you certain that you're allowed to do .htaccess on both sites? Link to comment Share on other sites More sharing options...
tryingtolearn Posted April 13, 2011 Author Share Posted April 13, 2011 Yes, The example I posted in post 4 works fine on both sites. I put a ticket in to the server support just to verify and they gave me a canned response that mod rewrite is enabled and that I would have to troubleshoot the code. and they cannot provide support for code yadayadayada Im reading up on the apache site all about re_write There has got to be something Im missing The dynamic links are fine but I really like the idea of it being SEO friendlier this way Plus - I really like learning the ins and outs Hell spent a ton of time with PHP and MySQL for Dynamic Web Sites(2nd Edition) and thats what got me into learning all this in the first place. So all in all its a positive! Great books! Link to comment Share on other sites More sharing options...
Larry Posted April 14, 2011 Share Posted April 14, 2011 Sorry, I missed that you had said that in your earlier posts. Okay, going with your second site, which seems to be working better, the URL http://www.acmaine.com/browse.php?type=coffee&category=Dark+Roast&id=2 works fine, showing no products found. But if you go to http://www.acmaine.com/browse/coffee/Dark+Roast/2, which should work, you get the error. Now the browse.php script shows that error if this conditional is false: if (!$type || !$sp_type || !$sp_cat || !$category) { So what you should do is echo out the values of all those variables in order to see which one is the problem. Then you can debug from there. Thanks for the nice words on the books! Link to comment Share on other sites More sharing options...
tryingtolearn Posted April 14, 2011 Author Share Posted April 14, 2011 All 4 vars are blank when I echo them out. So it still leads me to the rewrite rule not passing them. Changing RewriteRule ^browse/([A-Za-z\+\-]+)/([A-Za-z\+\-]+)/([0-9]+)$ browse.php?type=$1&category=$2&id=$3 to RewriteRule ^browse/coffee/Dark+Roast/2$ browse.php?type=$1&category=$2&id=$3 hasnt worked either which it should for just that particular llink anyway. Link to comment Share on other sites More sharing options...
Terry Posted April 14, 2011 Share Posted April 14, 2011 I would contact your host and ask them to check your site and make sure it is configured correctly. Just looking and seeing if mod_rewrite is turned on doesn't really check if there is a config issue somewhere. Any solid host will go that extra step and verify this when you ask. My host actually goes so far as creating files and folders in the sites space to verify things are working. if you create a php file with just phpinfo() and run it from within your site is php running as CGI or apache module? You should be able to see if mod_rewrite module shows up in the loaded modules but this does depend on how your host is configured. If all you ever get back from support is canned responses I would consider moving to a new host but that's just me. I would though make sure that your host does check out your account, there could be something screwy that is impacting that domain. I used to have an account at dreamhost and they had a utility that you could manually run and it would check for any issues but that wasn't always 100% either, best to have a real person go in and check things over. If they wont, or you just get canned responses... My current host has a 800 number I can call, support tickets via email and live online chat. Support is critical when it comes to your sites, consider switching if you don't get any. Link to comment Share on other sites More sharing options...
Larry Posted April 15, 2011 Share Posted April 15, 2011 All 4 vars are blank when I echo them out. So it still leads me to the rewrite rule not passing them. Yes, that would suggest your rewrite rule is not working. But it's working for the shop/sales link, and it's working well enough to get to browse.php. It's the backreferences that aren't working. As Terry suggests, I would recommend going back to your hosting company. Because the rule itself is written correctly. Any hosting company worth their salt ought to be able to help some. And if they won't, what good will they be when a serious problem comes up? RewriteRule ^browse/coffee/Dark+Roast/2$ browse.php?type=$1&category=$2&id=$3 hasnt worked either which it should for just that particular llink anyway. Well, that's not going to work because you've got no groupings in the match to use as the values for backreferencing in the redirect. Link to comment Share on other sites More sharing options...
tryingtolearn Posted April 16, 2011 Author Share Posted April 16, 2011 Well they are not worth their salt as I got no love from them at all since they just kept saying that since the basic rules worked the server was configured properly. So - I started looking into why the $_GET var wasnt getting passed in the "Pretty URL" style. Turns out through much reading multiviews is enabled on the server so Apache is trying to find filename to map the path. Causing shop/ or browse/ to become shop.php or browse.php prior to reaching the rewrite rule therefore not getting the match, the rule isnt executed. So for the time being I added Options -MultiViews to the .htaccess file and presto - It is working now working ex. Thanks to both of you for sticking w/ the post - Its throwing ideas around that usually lead me in the right directions to explore the possibilities. I really appreciate this forum!!! Learned a bunch along the way. Now Im just keeping my fingers crossed that by adding the line to the .htaccess I dont create a different problem as I go from here. 1 Link to comment Share on other sites More sharing options...
Larry Posted April 18, 2011 Share Posted April 18, 2011 Excellent! Kudos for figuring that out and thanks for sharing so that others might benefit! Glad it's working for you now. Link to comment Share on other sites More sharing options...
Recommended Posts