URL Rewriting Help

Discussion in 'Apache Migration/Compatibility' started by robfrew, Feb 3, 2011.

  1. robfrew

    robfrew New Member

    I need some help with some URL rewriting rules in .htaccess.

    The current setup I have does not work correctly. Here it is:

    Code:
    
    IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
    
    <Limit GET POST>
    order deny,allow
    deny from all
    allow from all
    </Limit>
    <Limit PUT DELETE>
    order deny,allow
    deny from all
    </Limit>
    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^domain.com [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]
    # If the requested file or directory don't exist then redirect to the
    # index.php and request the file. It will fetch it from the database
    # or generate a "not found" message
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^swift/p$ /swift/p/
    RewriteRule ^swift/p/$ /ext_forum.php
    RewriteRule ^swift/p/([0-9]+)$ /swift/p/$1/
    RewriteRule ^swift/p/([0-9]+)/$ /ext_forum.php?_p=$1
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^swift/i$ /swift/i/
    RewriteRule ^swift/i/$ /ext_post.php
    RewriteRule ^swift/i/([0-9]+)$ /swift/i/$1/
    RewriteRule ^swift/i/([0-9]+)/$ /ext_post.php?_i=$1
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^swift/i/([0-9]+)/p$ /swift/i/$1/p/
    RewriteRule ^swift/i/([0-9]+)/p/$ /ext_post.php?_i=$1
    RewriteRule ^swift/i/([0-9]+)/p/([0-9]+)$ /swift/i/$1/p/$2/
    RewriteRule ^swift/i/([0-9]+)/p/([0-9]+)/$ /ext_post.php?_i=$1&_p=$2
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^swift/(.+)/(.+)/([A-Z][A-Z])$ /swift/$1/$2/$3/ [NC, R]
    RewriteRule ^swifts/(.+)/(.+)/([A-Z][A-Z])/$ /swift/city.php?id=$2&state=$3&st=$1 [NC, L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([a-zA-Z0-9_-]+)$ u.php?u=$1
    RewriteRule ^([a-zA-Z0-9_-]+)/$ u.php?u=$1
    
    
    Essentially, what I need it to do is this. The first condition and rule redirects anyone who just types domain.com to www.domain.com.

    Code:
    RewriteCond %{HTTP_HOST} ^domain.com [NC]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]
    The 2 - 5 conditions and rules makes a php script search engine friendly.

    And the last condition and rule allows usernames in URLS to be passed to a php script.

    All of this works fine, except if I try to go to a real directory, it will not automatically pull up the index.php page. If I take away the url rewriting, it works again. For example, if I try to go to http://www.domain.com/mydir/, I get a page not found. However, if I go to http://www.domain.com/mydir/index.php, it works.

    Any ideas?

    Rob
  2. webizen

    webizen New Member

    Looks like DirectoryIndex isn't defined.

    Add 'DirectoryIndex index.php' to the top of .htaccess.
    Last edited: Feb 4, 2011
  3. mistwang

    mistwang LiteSpeed Staff

    For rewrite rule problem. just enable rewrite log, for vhost from httpd.conf, use directive
    "RewriteLogLevel 9" for that vhost, then check rewrite related log entries in the error log.

Share This Page