FAQ: mod_rewrite, 301 redirects, and optimizing Apache.

Discussion in 'Apache' started by Nintendo, Jul 30, 2005.

  1. joe_mat

    joe_mat Peon

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #721
    Hello,

    I am having a website where i am having dynamic URL pages in with .php extension.

    eg:http://www.mydomain.com/subcategory....name=nokia-n70

    i can have redirection code on. .htacces file like

    Options +FollowSymLinks
    RewriteEngine on


    RewriteRule ^category/([0-9]+)]+)/([0-9A-Za-z]+).html$ subcategory.php?subcatID=$1&subname=$2 [L]



    and on php page i having have code that create dynamic pages to static pages.

    echo "<a href='http://www.".$DOMAIN_NAME."/category/".$rw_sub[0]."/".
    format_str(stripslashes($rw_sub[1])).".html'>".$rw_sub[1]."</A></DIV>";



    it is creating my dynamic links to static links.
    http://www.mydomain.com/category/5/nokia-n70.html

    but when i click on that link i didn't find that pages there because i am not having that static html page on that specific static location.

    i just wanna know is it possible to have that static pages there without creating them manually.

    like if i have dynamic page as :
    http://www.mydomain.com/subcategory....name=nokia-n70

    and it became static as :
    http://www.mydomain.com/category/5/nokia-n70.html

    but can i have this static page there without make it manually on that location.

    Please suggest.

    Thanks
     
    joe_mat, Aug 27, 2007 IP
  2. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #722
    Hello,
    This should be simple:
    I need to rewrite results? as results.php?
    I just need to add the .php.
    Can you tell me how to do it?

    Thanks.
     
    Luke Jones, Aug 27, 2007 IP
  3. joe_mat

    joe_mat Peon

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #723
    I didn't get what you wanna say .

    Please explain it.
     
    joe_mat, Aug 27, 2007 IP
  4. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #724
    In one of my scripts the links returned are results?search_query=
    I have set up a page called results.php
    I need the links results?..... to go to results.php?....
    It's just adding the .php
    Do you know how to do this?

    Note: The links (results?...) were not created by me. They are returned from an RSS feed.)
     
    Luke Jones, Aug 27, 2007 IP
  5. joe_mat

    joe_mat Peon

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #725
    Hello,

    what my problem is that i have .haccess and php code make my menu link static from

    http://www.mydomain.com/subcategory....name=nokia-n70

    to

    http://www.mydomain.com/category/5/nokia-n70.html

    But when i click on these static link then its show me a blank page with " Page Cannot be

    found" error.
    because i am not having that static html page on that specific static location.

    It is nessecry to create that page nokia-n70.html manually there at specific location

    "http://www.mydomain.com/category/5/"

    Or it can be happen automaticlly
    please suggest
     
    joe_mat, Aug 27, 2007 IP
  6. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #726
    No nokia-n70.html type of files have to be created. Post a complete example of the original URL They all ahow up as
    mydomain.com/subcategory....name=nokia-n70

    Does that occure after pressing a forum button, or from a link in the script? I think the script needs to be edited some where. Mod_rewrite is for making URLs static looking.
     
    Nintendo, Aug 27, 2007 IP
  7. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #727
    It's the link of the keyword tags returned with Youtube videos.
    I can't change the results?... links. How do I create this page in my site?
    results with no .php
    ?
     
    Luke Jones, Aug 27, 2007 IP
  8. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #728
    mod_rewrite can't change them, the script would have to change it. mod_rewrite only makes fake URLs work. SEO wise, no .php is better than having .php.
     
    Nintendo, Aug 27, 2007 IP
  9. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #729
    Hello,
    How do you create these pages?
    Youtube is using them, so it must be possible to make them.
    Here's an example:
    /results?search_query=motors
    Is this a subfolder /results/ ?
    How do I make it?
     
    Luke Jones, Aug 28, 2007 IP
  10. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #730
    You have to figure out how to make the script spit it out with .php or the RSS feed if that doesn't have it.
     
    Nintendo, Aug 28, 2007 IP
  11. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #731
    I don't think it's possible because this link is inside the description tag.
    Again, if these pages exist in the Youtube site, then it's possible for me to make them in my site.
    How do I make them?
     
    Luke Jones, Aug 28, 2007 IP
  12. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #732
    If it's a php script, post in the php section with the code of the part of the script that keeps .php out. It's the script you need to change, not mod_rewrite.
     
    Nintendo, Aug 28, 2007 IP
  13. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #733
    Ok, I've done it!
    results? automatically goes to results/index.php
     
    Luke Jones, Aug 28, 2007 IP
  14. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #734
    Hello,
    I need to rewrite this url:
    http://buyacar.be/responses/?query=http://answers.yahoo.com/question/index?qid=20070904170434AAPqOPT
    PHP:
    to responses/http://answers.yahoo.com/question/index?qid=20070904170434AAPqOPT
    Any ideas?
    Would this be advantageous for search engine spiders?
     
    Luke Jones, Sep 5, 2007 IP
  15. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #735
    You can't. It would kill the script. Only if you add for example .html or change /responses/ to something else.

    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteBase /
    RewriteRule ^responses/(.*)\.html$ responses/whatever.php?query=$1 [L]
     
    Nintendo, Sep 5, 2007 IP
  16. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #736
    Hello,
    I tried this and it doesn't work.
     
    Luke Jones, Sep 5, 2007 IP
  17. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #737
    whatever.php is what ever the script name is.
     
    Nintendo, Sep 5, 2007 IP
  18. ForgottenCreature

    ForgottenCreature Notable Member

    Messages:
    7,473
    Likes Received:
    173
    Best Answers:
    0
    Trophy Points:
    260
    #738
    How can I redirect /forum/ to the main domain? I'm doing this now, need help!
     
    ForgottenCreature, Sep 5, 2007 IP
  19. downloadthenet

    downloadthenet Active Member

    Messages:
    497
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    78
    #739
    I can't believe you are still running this thread but it's great. Could you PLEASE hep me with my problem?

    I've add the simple forum plugin to my wordpress blog. I just want to make the forum url's static for search engines.

    The url's change depending on where you are.
    top level: schoolofhdtv.com/hdtv-forum
    inside a forum: schoolofhdtv.com/hdtv-forum?forum=1&page=1
    inside a post: schoolofhdtv.com/hdtv-forum?forum=1&topic=16&page=1

    I tried your tutorial, but I can't get it to do anything. The plugin is actually located in domain/wp-content/plugins/simple-forum/

    Of course, wordpress has it's own mod_rewrite, so I just need the code to effect the forum url's.

    Help would be greatly appreciated.
     
    downloadthenet, Sep 8, 2007 IP
  20. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #740
    What do you want them to look like?

    Options +FollowSymLinks +Indexes
    RewriteEngine on
    RewriteBase /

    For everything....

    RewriteRule ^forum/(.*)$ http://www.domain.com/$1 [R=301,L]

    or just /forum/

    RewriteRule ^forum/$ http://www.domain.com/ [R=301,L]
     
    Nintendo, Sep 8, 2007 IP