SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: simple mod_rewrite wont listen on unix

  1. #1
    SitePoint Addict
    Join Date
    May 2006
    Location
    Ljubljana
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple mod_rewrite wont listen on unix

    Hello,

    I have the following code in my .htaccess file (which works okay on my local server - wamp on win7):

    Code:
    RewriteEngine on
    RewriteCond $1 !^(images|system|js|themes|favicon\.ico|robots\.txt|index\.php) [NC]
    RewriteRule ^(.*)$ /index.php/$1 [L]
    When I move it to unix (cpanel) on some host provider that I have it wont rewrite as expected.

    What should I do?
    Is there any way to debug it to see whats going on?

    What else can I try?

    Thanks for help.

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,313
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    l2u,

    It should NOT work on your test server as the RewriteCond's $1 does not exist. That $1 should be %{REQUEST_URI}.

    At that point, the RewriteRule's use of the EVERYTHING atom is inappropriate (LAZY regez) which should loop were it not for the exclusion of the index.php script in the RewriteCond.

    In other words, you should learn some regex (you can start at the mod_rewrite tutorial Article linked in my signature).

    Redirect to /index.php/{yadda-yadda}? Horrors! Another person using MultiViews! WHY? IMHO, your host is smart enough to have disabled that (or left it disabled as I believe that's Apache's default).

    Finally, you didn't specify which version of Apache - it makes a difference if you're going to use the start anchor!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Addict
    Join Date
    May 2006
    Location
    Ljubljana
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How should I rewrite the third line then?

    What are multiviews and why should I avoid them?

    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^(images|system|js|themes|favicon\.ico|robots\.txt|index\.php) [NC]
    RewriteRule ^(.*)$ /index.php/$1 [L]
    Sorry for my noobness on this.

  4. #4
    SitePoint Addict
    Join Date
    May 2006
    Location
    Ljubljana
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should be more correct but still not working:

    Code:
    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^(images|system|js|themes|favicon\.ico|robots\.txt|index\.php)$ [NC]
    RewriteRule ^(.*)$ /index.php?%{REQUEST_URI}

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,313
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by l2u View Post
    How should I rewrite the third line then?
    By using regex to specify what you want to capture. EVERYTHING is NOT good regex - it's LAZY regex and causes more problems (with noobies) than it's worth.
    What are multiviews and why should I avoid them?
    It's a directive to Apache to serve a script which is sitting in the path position of a URI. IMHO, it's a dumb thing to do as it requires special parsing within the script.
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^(images|system|js|themes|favicon\.ico|robots\.txt|index\.php) [NC]
    RewriteRule ^(.*)$ /index.php/$1 [L]
    Sorry for my noobness on this.
    Did you bother to read my tutorial article?
    Quote Originally Posted by l2u View Post
    This should be more correct but still not working:

    Code:
    Options +FollowSymlinks
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^(images|system|js|themes|favicon\.ico|robots\.txt|index\.php)$ [NC]
    RewriteRule ^(.*)$ /index.php?%{REQUEST_URI}
    Argh! PLEASE have a read of the tutorial! Right now, you're just too far off the mark.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Addict
    Join Date
    May 2006
    Location
    Ljubljana
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I read your whole article (its very good) and I came to this:

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^/?(.*)$ /index.php/$1 [R=301,L]
    This will now work. However, if I remove R=301 (redirect) it wont work as supposed to.

    Any idea whys that? Must there be some bad configuration with apache or something I guess?

    Please dont mind (.*) - I know you're not a fan of this.

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,313
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    l2u,

    Thank you.

    The code you're using is a slight modification of WordPress's code which would be:
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^/?(.*)$ /index.php [L]
    The differences are:

    1. WP does NOT use MultiViews and

    2. WP does not make a permanent redirect.

    Quite obviously, their code works a charm across all the WP installations worldwide.

    The reason your code doesn't work is both the enumerated reasons above. MultiViews is (IMHO) poor technique and, making the redirection permanent, the resultant {REQUEST_URI} is no longer an existing directory OR a file. Moreover, without know WHY you're trying to do these (unusual) things, it's very difficult to understand why you're coding this way.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

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
  •