The MU forums have moved to WordPress.org

Two RewriteRule(s) explanation and question (6 posts)

  1. Paamayim
    Member
    Posted 16 years ago #

    Hi, I'm not much into mod_rewrite :(

    Could anyone please explain me what are the following rules for and if it may be safe to remove them?

    RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]

    About removing them, it's because they're causing Internal Server Errors sometimes dued to some modification to url management of external links (something like http://www.mysite.com/ext/www.external.com/somefile.php) when the external link ends with .php the server throws a 500.

    Thank you very much for the info.

  2. VentureMaker
    Member
    Posted 16 years ago #

    Why do you think these are causing 500 error? I would dig into errors log to check what exactly goes wrong.

  3. Paamayim
    Member
    Posted 16 years ago #

    Because if I comment them out, the error doesn't happen.

    They are not them alone obviously to generate the error, but in combination with custom tweaks, I suppose Apache cant find some .php file and throws the error, this file really doesn't exist locally because it's given in the url but it's an external link.

    Bad thing is I cannot access error log easily :(

  4. eagano
    Member
    Posted 16 years ago #

    If you are trying to load a real php file (ie, your somefile.php is an actual file on the filesystem in the DocumentRoot, it should load with no problems because of conditions that should exist above the rules you showed (as they exist in htaccess.dist):

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule . - [L]

    The '-f' is a condition that says 'if this is this a file', and the '-d' says 'if this is a directory'. The combination of these conditions and rule says 'if this is a file, OR if this is a directory, pass through with no changes and exit rewriting. That is why you can load some files directly, with no rewriting, like /wp-includes/js/autosave.js.

    The rules you asked about are to clean up paths to WP files. For exmple, the first rule will rewrite http://yourblog.com/nonexistentpath/wp-signup.php to http://yourblog.com/wp-signup.php.

    RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]

    Your URL is being rewritten by the second rule, because I assume that your somefile.php does not exist on the file system. It is being rewritten from http://www.mysite.com/ext/www.external.com/somefile.php to http://www.mysite.com/somefile.php. I would think that should throw a 404, not a 500.

    It's important to understand that mod_rewrite does not do redirection (in these cases), it does internal rewriting. If the user visits a URL that is re-written, they will still see the original url in their browser bar. Permalinks is the best example. http://yourblog.com/hello-world/ is actually http://yourblog.com/index.php?p=1

    The regular expressions used in these rules is too much to explain here. There is a good primer on the Apache website.

    I would definitely NOT remove these rules. You should be able to work around them.

  5. andrea_r
    Moderator
    Posted 16 years ago #

    "dued to some modification to url management of external links "

    I think the other posters missed this bit.

    Whatever you're using to change those external links is the issue.

  6. Paamayim
    Member
    Posted 16 years ago #

    > Whatever you're using to change those external links is the issue.

    I think this is a good point. I myself didnt' make the external link management, but after some digging into the code I found that it rely upon 404.php template page, inside it processes the URL using the part after /external/ to build a frame to load the external link in there, not a clean solution since it passes from a 404.

    Maybe I should redo this part myself. Do you guys have any idea on how to handle a wp/wpmu URL like http://<host>/external/<some-url&gt; so that I can call a template page, build frames in it and load in a frame <some-url>?

About this Topic

  • Started 16 years ago by Paamayim
  • Latest reply from Paamayim