1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice
  2. Dear Pleskians, please read this carefully! New attachments and other rules Thank you!
    Dismiss Notice
  3. Dear Pleskians, I really hope that you will share your opinion in this Special topic for chatter about Plesk in the Clouds. Thank you!
    Dismiss Notice

mod_rewrite Problems...

Discussion in 'Plesk for Linux - 8.x and Older' started by zeroborg, Apr 26, 2007.

  1. zeroborg

    zeroborg Basic Pleskian

    23
    57%
    Joined:
    May 8, 2006
    Messages:
    35
    Likes Received:
    0
    Hi all...

    I can't make mod_rewrite to work.
    I add the vhost.conf to /srv/www/vhosts/domain.com/conf with the following data:
    ===================
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^([^/]*)\.html$ /km/index.php?page=$1 [L]
    ===================

    I run /usr/local/psa/admin/sbin/websrvmng -v -a

    And when i try to see the result to page:
    http://www.domain.com/km/index.php?page=1000
    (which has to be retyped to: http://www.domain.com/1000.html )
    nothing happens...
    The rewrite works on the background. When i examined the logs of the rewrite engine i found that it PASSES THROUGH anything...
    ==================
    (2) init rewrite engine with requested uri /km/index.php
    (3) applying pattern '^([^/]*)\.html$' to uri '/km/index.php'
    (1) pass through /km/index.php
    ==================

    Does anyone knows why? Please advise.
    Thank you.

    Zeroborg.
     
  2. stupidnic

    stupidnic Guest

    0
     
    I am confused.

    Are you trying to rewrite the pattern *.html to /km/index.php?page=$1 or are you trying to rewrite the pattern /km/index.php?page=* to $1.html?

    Your rewrite rule will match something.html and rewrite it to /km/index.php?page=something

    Is that what you are trying to accomplish?
     
  3. JUSTbiz

    JUSTbiz Guest

    0
     
    you should try it in...

    .htaccess of the httpdocs.. I have managed to get it working on mine.

    you don't need the Symlink part..
     
  4. zeroborg

    zeroborg Basic Pleskian

    23
    57%
    Joined:
    May 8, 2006
    Messages:
    35
    Likes Received:
    0
  5. stupidnic

    stupidnic Guest

    0
     
  6. zeroborg

    zeroborg Basic Pleskian

    23
    57%
    Joined:
    May 8, 2006
    Messages:
    35
    Likes Received:
    0
  7. stupidnic

    stupidnic Guest

    0
     
    Alright, we are now on the same page.

    You can do this in a couple of ways, but probably the easiest is going to be to create an .htaccess file in the root of the site.

    Obviously you have mod_rewrite working.

    Here is a sample of what I have been using for a similar rewrite situation. I will explain each line in a little more detail to help you understand what is going on.

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)\.html$ /km/index.php?page=$1 [L]
    
    Here is what each line does:

    RewriteEngine On

    This turns on the rewrite engine

    RewriteCond %{REQUEST_FILENAME} !-f

    This line checks to make sure the requested file does not exist. This is handy to prevent requests for legitimate files from being passed through to the mod_rewrite rule that follows.

    RewriteRule ^(.*)\..html$ /km/index.php?page=$1 [L]

    This looks for anything ending in .html and passes the pattern before that to /km/index.php?page= in the value of $1.

    A word of caution: this rule is "greedy" meaning it can match A LOT of patterns you might not want it to match. Make sure you test it and that it behaves how you expect it to. This will also match requests for files in subdirectories too (/foo/bar/something.html) and will pass that entire string to your page variable.

    Good luck.
     
Loading...