SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A little htaccess help

    I'm moving a site to a new host and keeping the same domain name. Seems the same unaltered htaccess file would work for me...

    Here's what I've got:
    ------------------------------------------
    DirectoryIndex index.php
    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/(.*)$ index.php?var1=$1 [L,QSA]
    --------------------------------------------

    The file is being recognized, as it properly going to index.php.

    However, nothing else is working.

    First, I'm having to use a temporary url to browse the site until we switch the domain pointers. Looks like:
    http://myipaddress/~myusername/

    This properly resolves to the index page.

    These work on the old site:
    http://www.mysite.com/index.php?var1=faq
    http://www.mysite.com/index.php?var1=contact
    http://www.mysite.com/index.php?var1=privacy-statement

    Also on the old site, these redirect properly to the above:
    http://www.mysite.com/faq
    http://www.mysite.com/contact
    http://www.mysite.com/privacy-statement

    These work on the NEW site:
    http://myipaddress/~myusername/index.php?var1=faq
    http://myipaddress/~myusername/index.php?var1=contact
    http://myipaddress/~myusername/index.php?var1=privacy-statement

    These do NOT work on the new site...
    http://myipaddress/~myusername/faq
    http://myipaddress/~myusername/contact
    http://myipaddress/~myusername/privacy-statement

    Suggestions?

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,278
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    I think you have a stray slash.

    RewriteRule ^/(.*)$ index.php?var1=$1 [L,QSA]

    ..should be...

    RewriteRule ^(.*)$ index.php?var1=$1 [L,QSA]

    Frankly, I'm surprised this worked on the old site.
    "First make it work. Then make it better."

  3. #3
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    With the slash, clicking on a link "contact", takes me to:
    http://myipaddress/~myusername/contact ... and a 404 on the page

    Without: RewriteRule ^(.*)$ index.php?var1=$1 [L,QSA] - clicking a link "contact" takes me to:
    http://myipaddress/404.html

    Tried it both ways previously...

    If I change the link itself to "/contact" ...
    Same thing as the above.

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

    The leading / is only required in the older (now ancient) Apache 1 servers so eliminate it as Jeff suggested.

    Quote Originally Posted by LesMizzell View Post
    With the slash, clicking on a link "contact", takes me to:
    http://myipaddress/~myusername/contact ... and a 404 on the page

    That's a sign that the Apache server needs a restart. If it's on a hosted site, contact the sys admins, otherwise, use the Apache monitor and simply restart.

    Without: RewriteRule ^(.*)$ index.php?var1=$1 [L,QSA] - clicking a link "contact" takes me to:
    http://myipaddress/404.html

    Why would you QSA this?

    Tried it both ways previously...

    Someone's upgraded to Apache 2 on you! They did you a favor but you need to remove the leading / (after the ^)!

    If I change the link itself to "/contact" ...
    Same thing as the above.

    Yup!
    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, 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

  5. #5
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,278
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    The leading / is only required in the older (now ancient) Apache 1 servers...
    That's actually not correct, as I've already explained. I've given you the exact spot in the documentation you need to check, and I've given you repeatable steps to test the behavior in Apache itself.

    Quote Originally Posted by dklynn View Post
    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.
    Unfortunately anyone who learns from this tutorial will have to unlearn some incorrect information later on (the above is one such example). I strongly recommend that anyone who's interested in this topic go straight to the definitive source for the most complete, authoritative, and correct information.
    "First make it work. Then make it better."


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
  •