SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Ohio
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    looking for the wrong page?

    Hey,

    Iím trying to optimize a site for some SEO stuff. One thing I want to do is stop using query strings and start making the URLs look like they point to .html files. For example I plan on changing mysite.com/news.php?news_is=125 to mysite.com/news.php/125/i_love_seo.html. I know what I need to do for this in PHP (Iíve done it on another site before) however I dont know what I need to do in apache. When I try in apache it looks for i_love_seo.html and not news.php. How do I get apache to recognize that I want news.php and not i_love_seo.html?

  2. #2
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok well you can't magically convert newsid's into newstitles using apache so the first thing you need to consider is when generating your URLs to the news article to use PHP to output a relevant news title.

    Use this within a .htaccess file in your site root:
    Code:
    RewriteEngine On
    RewriteRule ^news/([0-9]+)/([A-Za-z0-9_]+)\.html$ news.php?news_is=$1 [L]
    As long as your url is in the format mysite.com/news.php/125/i_love_seo.html then that above rule will work. Be sure to only include A-Z (upper and lower case), digits and underscores in your news title.

    Good luck!
    - Dean

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    TN,

    Dean's almost correct in saying that you can't convert from numeric id to title in Apache (RewriteMap will do that but you'll have to code that for every new article).

    However, there was another thread started recently about using article titles in the URL and the CORRECT answer was that it can be done. This is a little different than what you were asking but the direct route is the best and can be initiated in PHP and the correct article served from your db by PHP.

    The article at datakoncepts.com/seo addresses setting up Apache for mod_rewrite through these SEO redirects and off into the way to use titles - provided they're keys in your db and don't contain spaces. That thread's initiator was happy with what he found there, you may be, too.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Ohio
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried the mod rewrite test in the link dklynn gave me. however I got an Internal Server Error. when I looked in Apache's error log it said this "Invalid command 'RewriteEngine', perhaps mis-spelled or defined by a module not included in the server configuration".

    what should I do?

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    TN,

    RewriteEngine On/Off is a valid Apache command (when the mod_rewrite module has been included by the httpd.conf directives. Did you check that those were properly set AND restart Apache if you removed the comments?

    Anyway, if Apache is complaining about the RewriteEngine On (and mod_rewrite is included), try removing that directive (to mod_rewrite). However, I'm sure that you don't have mod_rewrite included so that's the first place to look.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Ohio
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess I forgot to include mod_rewrite.c

    anyway, one last question and then I think Ive got the hang of it.

    I want photos/pp/1/birds.html to point to photos.php?p=pp&photo_id=1&d=birds so this is what I have in .htaccess

    RewriteRule ^photos/pp/([0-9]+)/([a-zA-Z0-9_]+)\.html$ photos.php?p=pp&photo_id=$1&f=$2 [L]
    however this doesnt seem to work. what am I doing wrong?

    Thanks! you have been a huge help!

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    TN,

    You have the same problem I do: Dyslexic fingers! Is that supposed to be a "d" or an "f"?

    Quote Originally Posted by TNGraham
    I guess I forgot to include mod_rewrite.c

    anyway, one last question and then I think Ive got the hang of it.

    I want photos/pp/1/birds.html to point to photos.php?p=pp&photo_id=1&d=birds so this is what I have in .htaccess

    Code:
    RewriteRule ^photos/pp/([0-9]+)/([a-zA-Z0-9_]+)\.html$ photos.php?p=pp&photo_id=$1&f=$2 [L]
    however this doesnt seem to work. what am I doing wrong?

    Thanks! you have been a huge help!
    You're very welcome!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  8. #8
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to put RewriteEngine On above that line TnGraham

  9. #9
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Ohio
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is my .htaccess file

    ErrorDocument 404 http://localhost/web/index.php

    RewriteEngine On

    #photos
    RewriteRule ^photos/pp/([0-9]+)/([a-zA-Z0-9_]+)\.html$ photos.php?p=pp&photo_id=$1&seo_file=$2 [L]
    RewriteRule ^photos$ photos.php [L]

    # force type
    <Files about>
    ForceType application/x-httpd-php
    </Files>
    the problem is that It gives me a 404 page when I go to http://localhost/web/photos/pp/1/birds.html

  10. #10
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is your .htaccess file within the web directory?

  11. #11
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Ohio
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep, its at /web/.htaccess

  12. #12
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well it looks like you either a) do not have mod_rewrite enabled or b) have a corrupt module.

    I don't think there is much else we can help you with

  13. #13
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Ohio
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think your right, there is something wrong with mod_rewrite on my computer since I got it to work on another server. I guess I'll look into that problem sometime (but not now since i have to finish a site for a client).

    Thanks for you help!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •