Jeffro Posted November 2, 2011 Share Posted November 2, 2011 Hi all. okay.. so I've failed miserably at rewriting my url. Here's the story.. My site currently displays like this (when clicking on a listing from my home page): hxxp://mysite.com/viewItem.php?id=10 I would LOVE for the urls to read: hxxp://mysite.com/121/border-collie-for-sale-to-good-home where 121 is always the $row['postId']; and "border-collie-for-sale-to-good-home" is always my $row['title']; Question 1: I did figure out how to make it work this way (solely through my php code): hxxp://www.mysite.info/viewItem.php?id=121/border-collie-for-sale-to-good-home -- If I just keep it like this, do you think the SEO benefit is the same as if the viewItem.php?id=121 wasn't there... since the title is appended to the end? Question 2: Any idea why I can't seem to make the url rewrite? I would gladly list all the ways I've tried had I recorded them, but I have spent the last 3 hours making changes that do nothing. It always shows the same (as I show in the first bit of code above). I've read about 10 different tuts, including this last one (http://www.easymodrewrite.com/guide-syntax), which seems to be setup the same way as my page, so I was hopeful... but nothing. I did throw some garbled characters in the .htaccess file to verify it was being recognized. Thanks for any assistance! Quote Link to comment https://forums.phpfreaks.com/topic/250268-have-tried-all-night-to-rewrite-my-url/ Share on other sites More sharing options...
Jeffro Posted November 2, 2011 Author Share Posted November 2, 2011 By the way.. if anyone is interested in making this work, I'll gladly pay $50 and setup an isolated environment for you to login to. This is a simple classified script that I did not create but there's not much to it. Let me know if you have any interest. I'll pay w/ PayPal immediately following. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/250268-have-tried-all-night-to-rewrite-my-url/#findComment-1284152 Share on other sites More sharing options...
Jeffro Posted November 2, 2011 Author Share Posted November 2, 2011 This is my most recent attempt: ErrorDocument 404 /index.php RewriteEngine on # RewriteBase / RewriteRule ^viewItem/([0-9]+)$ viewItem.php?id=$1 ...and then I called my url to: <a href="viewItem.php?id=<?php echo $postid;?>/<?php echo $thetitle;?>" ($postid and $thetitle are both populated with the database results for their respective columns.) Is this my problem? If I rewrite the url in htaccess and then call it like this, am I doing it wrong? Quote Link to comment https://forums.phpfreaks.com/topic/250268-have-tried-all-night-to-rewrite-my-url/#findComment-1284154 Share on other sites More sharing options...
cags Posted November 2, 2011 Share Posted November 2, 2011 OK, so we have a page on our site that works, it's a post with the id of 121 and is accessed via the URL http://mysite.com/viewItem.php?id=121, this is all fine and dandy but it's not as pretty as we would like to be, we want people to access it via http://mysite.com/121/border-collie-for-sale-to-good-home. Step 1: We need to use mod_rewrite in order to take a request for /121/border-collie-for-sale-to-good-home and serve up /viewItem.php?id=121. RewriteEngine On RewriteRule ^([0-9]+)/[a-z-]+/?$ /viewItem.php?id=$1 [L] We should now be able to type /121/border-collie-for-sale-to-good-home into our address bar, and view the page. Step 2: We need to update the links in our script so that they link to this newly beautified url. <a href="/<?php echo $postid;?>/<?php echo $thetitle;?>" Step 3: Celebrate. There are various nuances that can trip you up along the way, but this is essentially all the steps required. Quote Link to comment https://forums.phpfreaks.com/topic/250268-have-tried-all-night-to-rewrite-my-url/#findComment-1284390 Share on other sites More sharing options...
Jeffro Posted November 11, 2011 Author Share Posted November 11, 2011 cags.. I love you. I tried everything and your solution did it! THANK YOU!! I didn't realize you had provided the solution and was checking back tonight after being away a while. I gave it a whirl and voila!! You're my hero dude. Thx again! Quote Link to comment https://forums.phpfreaks.com/topic/250268-have-tried-all-night-to-rewrite-my-url/#findComment-1287264 Share on other sites More sharing options...
cags Posted November 11, 2011 Share Posted November 11, 2011 I'm glad it worked Quote Link to comment https://forums.phpfreaks.com/topic/250268-have-tried-all-night-to-rewrite-my-url/#findComment-1287280 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.