Jump to content

Have tried all night to rewrite my URL!


Jeffro

Recommended Posts

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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? 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

  • 2 weeks later...

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.