SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 33 of 33

Thread: mod_rewrite on WinXP working strangely

  1. #26
    SitePoint Enthusiast -saturn-'s Avatar
    Join Date
    Nov 2003
    Location
    Thessaloniki, Greece
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure! Here you go.
    Attached Files

  2. #27
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At a first glance you forgot this line:

    NameVirtualHost *

    So un comment it where you find this:
    #
    # Use name-based virtual hosting.
    #
    NameVirtualHost *


    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  3. #28
    SitePoint Enthusiast -saturn-'s Avatar
    Join Date
    Nov 2003
    Location
    Thessaloniki, Greece
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right on the spot!

    Thanks again, pippo!

  4. #29
    SitePoint Enthusiast -saturn-'s Avatar
    Join Date
    Nov 2003
    Location
    Thessaloniki, Greece
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Having worked a bit on mod_rewrite and come up with my own rules, I came back here to ask yet another question.

    So, hi everyone!

    My .htaccess file looks like this:

    Code:
    RewriteEngine On
    RewriteRule ^(en|el)/services(/?)$ services.php?lang=$1 [L]
    RewriteRule ^(en|el)/services/service([0-9]+).html$ services.php?lang=$1&id=$2 [L]
    RewriteRule ^(en|el)/clients/?$ clients.php?lang=$1 [L]
    RewriteRule ^(en|el)/clients/type([0-9]+)(/project([0-9]+))?.html$ clients.php?lang=$1&type=$2&pid=$4 [L]
    RewriteRule ^(en|el)/news/?$ news.php?lang=$1 [L]
    RewriteRule ^(en|el)/news/announcement([0-9]+)/?.html$ news.php?lang=$1&cid=$2 [L]
    RewriteRule ^(en|el)/casestudies(/?)$ casestudies.php?lang=$1 [L]
    RewriteRule ^(en|el)/casestudies/study([0-9]+).html$ casestudies.php?lang=$1&cid=$2 [L]
    RewriteRule ^(en|el)/showcase(/?)$ showcase.php?lang=$1 [L]
    RewriteRule ^(en|el)/showcase/show([0-9]+).html$ showcase.php?lang=$1&cid=$2 [L]
    If I go to http://www.zefxis.local/en/services/service1.html the URI is nicely re-written, but it takes about 5 seconds for the page to be displayed (I'm working locally, by the way).

    Checking the mod_rewrite log file (which from 0 bytes becomes 166KBs as soon as I visit the page I mentioned before) I see that although the pattern is applied to the URI it tries to apply the next rule as well.

    I'm including a ZIP file with the log so you can check it out and tell me what you think.

    Thanks in advance!
    Attached Files

  5. #30
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all, compliments because the best way to learn mod_rewrite is to look at his logs.
    It's like as programming in C, learning how the C is translated in assembly helps a bit .
    Motto of the day for mod_rewrite:
    ``RewriteLog and RewriteLogLevel are your friends''

    That, said.
    Confused about that long file ? You should be!

    You don't have to worry though because for each request mod_rewrite will try to see if the uri will apply to one of those rules.
    So if your page will contain for example 50images then for each images mod_rewrite will try to execute all the rules.

    Also you can see from the first lines of your log file the internal redirection is fine.

    Suggestions:
    a)
    try to test calling services.php?lang=en&id=1 directly
    and check if your system is still slow

    b)
    try adding this rule:

    RewriteEngine On
    RewriteRule \.(php|css|jpe?g|gif)$ - [L]
    your rules here

    stop apache, delete your log files, relaunch apache and you will your log file a bit shorter, the perfomance should be increased a bit too...



  6. #31
    SitePoint Enthusiast -saturn-'s Avatar
    Join Date
    Nov 2003
    Location
    Thessaloniki, Greece
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi pippo and thanks for replying again!

    I used the RewriteRule you provided (after inlcuding js) in it and it worked. (the log file is now 0KBs !!!)

    What exactly did that do? The fact that you included .php confused me, because otherwise I'd think that the rule just said "ignore these extensions", but is this the case here?

    PS: I also tried calling services.php?lang=en&id=1 directly and the loading time is still long? What could be going wrong?

  7. #32
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes,
    you have to specify the extension you don't want to be parsed by mod_rewrite rules.
    In your rules you only used .html so when a .php is typed we can avoid mod_rewrite to do some works.

    The aim of
    RewriteRule \.(php|css|jpe?g|gif)$ - [L]
    is:
    if the extension is .php or .css or .etc then do ``-'' which means ``do nothing, exit from mod_rewrite (the L flag forces the exit) ''.
    The ``do nothing'' means ``mod_rewrite does nothing'', so if you call services.php then mod_rewrite will call directly the services.php skipping to parse the following rules.
    This trick is nice so it will avoid at mod_rewrite to try to parse the following rules.

    The fact that calling.php it takes a lot of seconds it's something about your .php script and not about mod_rewrite.
    Maybe you have an ad banner and that could be the reason that it takes some seconds to execute.
    For the .php issue I'd suggest to post the question to the smart php guys here at sitepoint forums.


    Hope with my confused English it was a bit clear!


    p.s.
    I have to go out for few hours,
    if something is still not clear about mod_rewrite do not hesitate to ask obviously

  8. #33
    SitePoint Enthusiast -saturn-'s Avatar
    Join Date
    Nov 2003
    Location
    Thessaloniki, Greece
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot, pippo!

    Have a nice night!

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
  •