SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict MikesBarto2002's Avatar
    Join Date
    May 2006
    Location
    New York City
    Posts
    317
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 404 Error - Apache config and mod_rewrite - Something wrong!

    Hello all! I am new to Apache and trying to make it work, so here's my problem. I have created a rewrite rule, and it is not rewriting.

    My folder structure is as follows:

    root/
    genesis/
    index.php
    .htaccess

    I checked to make sure that the rewrite module is being loaded in my httpd.conf file.

    Then, I put the following in my virtual host file:

    Code:
    <VirtualHost *:80>
            DocumentRoot "/Users/barryhjames/Sites/stwilliamtheabbot"
            ServerName stwilliam
            ErrorLog "/Private/var/log/apache2/stwilliam-error_log"
            RewriteLog "/Private/var/log/apache2/stwilliam-rewrite_log"
            RewriteLogLevel 9
            <Directory /Users/barryhjames/Sites/stwilliamtheabbot>
                    Options Indexes FollowSymLinks MultiViews
                    AllowOverride None
                    Order allow,deny
                    Allow from all
            </Directory>
    </VirtualHost>
    And then this is what my .htaccess file looks like:

    Code:
    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
            
    RewriteRule ^(.+)$ /index.php?url=$1 [QSA,L]
    Basically, I want whatever someone types in after /root/genesis/ to re-route to /root/genesis/index.php.

    Any help would be much appreciated!
    James Web Development | New York, NY
    Design, Develop, Deliver

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Are you using the latest version of Apache? If so instead of using mod_rewrite use FallbackResource. (Can be defined in .htaccess just the same.)

    Otherwise might try this:
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .? /index.php?url=%{REQUEST_URI} [L,QSA]
    Alternatively. Instead of passing "url" in the query string you can use $_SERVER['REQUEST_URI'] to get the same thing.

    Thus it becomes: RewriteRule .? /index.php [L,QSA]
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,680
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    l_e,

    Nicely done!

    MB,

    mod_rewrite requires AllowOverride ALL so you've effectively disabled it. Additionally, RewriteLogLevel 9 is great for following mod_rewrite logic but it should never be used on a production server.

    Likewise, if you understand MultiViews (and how to keep away from problems), fine, but it seems to cause more problems than it's worth (my recommendation is -MultiViews).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    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
  •