#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    120
    Rep Power
    45

    .htaccess some rewriterules dont work anymore after upgrade php & mysql


    Recently I let my host upgrade the php and mysql versions i am using. Not sure if this has something to do with it but now some rewriterules in my htacces file for a site of mine are not working anymore.

    These rewrites still work:
    Code:
    Options +FollowSymLinks
    RewriteEngine on
    # force www
    RewriteCond %{HTTP_HOST} ^mydomain\.com$
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
    # wp site redirects
    RewriteRule ^2006(.*)$ http://www.mydomain.com/wpsitebackup/2006$1 [R=301,L]
    RewriteRule ^2007(.*)$ http://www.mydomain.com/wpsitebackup/2007$1 [R=301,L]
    RewriteRule ^2008(.*)$ http://www.mydomain.com/wpsitebackup/2008$1 [R=301,L]
    But these following rewriterules are not working anymore:
    Code:
    # newscript rewrites
    RewriteRule ^out/([0-9]+)/([^/]+)$ http://www.mydomain.com/out.php?id=$1
    RewriteRule ^out/([0-9]+)/([^/]+)/$ http://www.mydomain.com/out.php?id=$1
    RewriteRule ^category/([^/]+)$ http://www.mydomain.com/index.php?cat=$1
    RewriteRule ^category/([^/]+)/$ http://www.mydomain.com/index.php?cat=$1
    RewriteRule ^page/([0-9]+)$ http://www.mydomain.com/index.php?page=$1
    RewriteRule ^page/([0-9]+)/$ http://www.mydomain.com/index.php?page=$1
    RewriteRule ^category/([^/]+)/page/([0-9]+)$ http://www.mydomain.com/index.php?page=$2&cat=$1
    RewriteRule ^category/([^/]+)/page/([0-9]+)/$ http://www.mydomain.com/index.php?page=$2&cat=$1
    I didnt change anything to the site, it used to work perfect but now it doesnt... hope someone knows what is wrong
    woozy.
  2. #2
  3. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,977
    Rep Power
    9647
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    120
    Rep Power
    45
    When i click a category link, for example: http://www.mydomain.com/category/pics/
    It goes to the original link of the script: http://www.mydomain.com/index.php?cat=pics
    And not http://www.mydomain.com/category/pics/ which it went to when it used to work.

    So it still goes to the correct pages, but the url rewrites dont work anymore. And i dont know how this is possible all of a sudden.
    woozy.
  6. #4
  7. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,977
    Rep Power
    9647
    If you put a http://... in the replacement, Apache will actually redirect the user to that address. Doesn't matter if it's the same domain name.

    If you don't want to see the redirect, remove everything up to the path.
    Code:
    RewriteRule ^out/([0-9]+)/([^/]+)$ out.php?id=$1

    Comments on this post

    • jharnois agrees
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    120
    Rep Power
    45
    Thanks alot, its working like it should again. But how come it always used to work too with the http:// and all of a sudden it didnt anymore?
    And could you explain what you mean by actually redirecting? Is it that with this rule it just rewrites the url, but with http:// in it, it also redirects? Does google look at my site now like it has duplicate content (i.e. do i need to redirect index.php?cat=pics etc. to the desired rewritten url?)
    Last edited by wouz; September 27th, 2010 at 04:18 AM.
    woozy.
  10. #6
  11. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,800
    Rep Power
    1104
    Originally Posted by requinix
    If you put a http://... in the replacement, Apache will actually redirect the user to that address. Doesn't matter if it's the same domain name.
    I, too, have found this to be the case in practice, but the documentation indicates otherwise
    If an absolute URL is specified, mod_rewrite checks to see whether the hostname matches the current host. If it does, the scheme and hostname are stripped out and the resulting path is treated as a URL-path. Otherwise, an external redirect is performed for the given URL. To force an external redirect back to the current host, see the [R] flag below.
    Originally Posted by wouz
    But how come it always used to work too with the http:// and all of a sudden it didnt anymore?
    It's probably safe to assume that if your host upgraded PHP and MySQL, they upgraded Apache, too. There are some slight variations in mod_rewrite from version to version .. the regular expression library at the very least .. that could cause the results of the same code to change slightly.
    And could you explain what you mean by actually redirecting?
    A redirect changes the web address and causes the browser to make a second request. A redirect is visible by the visitor; a rewrite is not.

    BTW
    Code:
    RewriteRule ^out/([0-9]+)/([^/]+)$ http://www.mydomain.com/out.php?id=$1
    RewriteRule ^out/([0-9]+)/([^/]+)/$ http://www.mydomain.com/out.php?id=$1
    can be shortened to:
    Code:
    RewriteRule ^out/([0-9]+)/([^/]+)/?$ http://www.mydomain.com/out.php?id=$1

    Comments on this post

    • requinix agrees : you are indeed correct
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    120
    Rep Power
    45
    thank you very much for that explanation
    woozy.

IMN logo majestic logo threadwatch logo seochat tools logo