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

    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Cool New rule to .htaccess file don't work on live site :(


    I had to add a rule to the .htaccess file of existing site, which redirect from some old images urls -> to the new ones. So, directly after the

    RewriteEngine On

    I added my new rule:

    RewriteRule ^images/photos/(.+) /media/projects/$1 [L]

    Locally and on the dev server - all is fine! But when I deployed it on the live site - it's not working ...

    Locally I'm on OpenSUSE, the dev server is on Ubuntu Server, and the live server is FreeBSD. I ran phpinfo() and it showed that on the live server (shared hosting) I have mod_rewrite, so I don't know what could the problem be. Tried to add some "Options" to the .htaccess file, tried with flag for redirect in the end of the new rule ... but nothing changed.

    All the other rules are working. When I break something in the .htaccess file - it gives me "Internal server error", and if I write "Deny from all" - it gives me "Forbidden" - as it should.

    Can you help me? ... Thanks in advance
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,056
    Rep Power
    9398
    Try using
    Code:
    RewriteRule ^/?images/photos/(.+) /media/projects/$1 [L]
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Cool ...


    It didn't work ...

    I tried

    RewriteRule ^images/photos/(.+) /media/projects/$1 [L]
    RewriteRule ^/images/photos/(.+) /media/projects/$1 [L]
    RewriteRule ^/?images/photos/(.+) /media/projects/$1 [L]

    but none of these worked ...
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,056
    Rep Power
    9398
    ...You probably have a /media folder in the root of your filesystem don't you? If Apache sees the root folder exists, and it won't check subfolders, then it assumes your "/media" actually means that root folder and not a path within your document root.

    No leading slash.
    Code:
    media/projects/$1
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Cool Hm ... :) ...


    Well, the structure of the project is:

    /
    |- application
    |- public
    \- .htaccess

    So, I'm adding the rules to this top-level ".htaccess".

    This folder - "media" - is in that "public" folder. So, I tried so many things for this rule:

    RewriteRule ^images/photos/(.+) media/projects/$1 [L]
    RewriteRule ^/images/photos/(.+) media/projects/$1 [L]
    RewriteRule ^/?images/photos/(.+) media/projects/$1 [L]

    RewriteRule ^images/photos/(.+) /media/projects/$1 [L]
    RewriteRule ^/images/photos/(.+) /media/projects/$1 [L]
    RewriteRule ^/?images/photos/(.+) /media/projects/$1 [L]

    RewriteRule ^images/photos/(.+) public/media/projects/$1 [L]
    RewriteRule ^/images/photos/(.+) public/media/projects/$1 [L]
    RewriteRule ^/?images/photos/(.+) public/media/projects/$1 [L]

    RewriteRule ^images/photos/(.+) /public/media/projects/$1 [L]
    RewriteRule ^/images/photos/(.+) /public/media/projects/$1 [L]
    RewriteRule ^/?images/photos/(.+) /public/media/projects/$1 [L]

    ...

    In all cases - it's behaving like it "can not match" the first part of the rules ... I guess ...

    And the working variant - locally and on the dev server - is:

    RewriteRule ^images/photos/(.+) /media/projects-oldsite/$1 [L]
  10. #6
  11. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,056
    Rep Power
    9398
    I meant "root of the filesystem" as in the root of the filesystem, not of your website. As in /media and not /var/www/public/media.

    Code:
    RewriteRule ^/?images/photos/(.+) media/projects/$1 [L]
    should work correctly.

    Try
    Code:
    RewriteRule ^/?images/photos/1$ 1.jpg [L]
    RewriteRule ^/?images/photos/2$ media/2.jpg [L]
    RewriteRule ^/?images/photos/3$ media/projects/3.jpg [L]
    and create those three .jpg files (using any image you want). Then try the three corresponding URLs. Do any of them work?
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Wink Voila ... :) ...


    Well, after some experiments I did - some of them prompted by requinix - I figured out what the problem was ...

    So, the structure of the application is this one:

    / - root
    |- application
    |- public
    | |- css,images, etc ...
    | \- .htaccess
    \- .htaccess

    So, the virtual hosts - local and on dev - is pointing to the "root" while on the live site the domain appears to point to the "public" folder. And so, when I put the rules on the "public" .htaccess file - then it all worked on the live site.
    (And what was confusing for me is that when I break the "root" .htaccess file - the live site gives Error 500 ... and that's why I thought the "root" .htaccess file is the one that I should use ...)

    So, marking as "solved" ...
    And to requinix ... thanks girl ...

IMN logo majestic logo threadwatch logo seochat tools logo