Help me to merge 2 mod_rewrite rule - $10!

Discussion in 'Apache' started by manov, Aug 2, 2007.

  1. #1
    Hello Server guru.

    I've a CMS and wordpress blog installed on the root of my site (mistake, I should have installed WP on a sub folder)

    So my .htaccess file contains two mod_rewrite rule one for Wordpress and another one for other CMS. Below is the code

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress

    AddHandler server-parsed .html
    AddHandler server-parsed .htm
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([A-Za-z0-9-]+)/?$ cat.php?pagename=$1 [L]
    RewriteRule ^([A-Za-z0-9-]+)/?.html$ cat.php?pagename=$1 [L]
    RewriteRule category(.*)/(.*)\.html$ /cat.php?Start=$1&pagename=$2 [L]
    RewriteRule category(.*)/(.*)/$ /cat.php?Start=$1&pagename=$2 [L]
    RewriteRule page(.*)\.php$ /item.php?item=$1 [L]​

    Now the second rule is not working. But if I put second rule above the wordpress rule it works... but wordpress doesn't work :(

    It looks like both rules can be merged to single. So please help me... I'll send $10 to your PP account if it is successful

    Thanks :)
    Mahesh Bhat
     
    manov, Aug 2, 2007 IP
  2. manov

    manov Well-Known Member

    Messages:
    151
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #2
    Oops... 50 views but no response!

    AMAZING.... I thought there are too many intelligent techy guys here ;)
     
    manov, Aug 2, 2007 IP
  3. ndreamer

    ndreamer Guest

    Messages:
    339
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #3
    try something like.

    AddHandler server-parsed .html
    AddHandler server-parsed .htm
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([A-Za-z0-9-]+)/?$ cat.php?pagename=$1 [L]
    RewriteRule ^([A-Za-z0-9-]+)/?.html$ cat.php?pagename=$1 [L]
    RewriteRule category(.*)/(.*)\.html$ /cat.php?Start=$1&pagename=$2 [L]
    RewriteRule category(.*)/(.*)/$ /cat.php?Start=$1&pagename=$2 [L]
    RewriteRule page(.*)\.php$ /item.php?item=$1 [L]
    RewriteRule . /index.php [L]
     
    ndreamer, Aug 3, 2007 IP
  4. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #4
    ndreamer, that will probably cause problems. The RewriteCond used to check if the request is not for a existing file or directory is not applied to the last rule for example. Also, all you did was copy the rules over. The problem was most likely in this line used for the blog:
    RewriteRule ^([A-Za-z0-9-]+)/?$ cat.php?pagename=$1 [L]
    Code (markup):
    That conflicts with the WordPress rule:
    RewriteRule . /index.php [L]
    Code (markup):
    I think you will have to do without that rule for the blog:

    This should work:
    AddHandler server-parsed .html
    AddHandler server-parsed .htm
    Options +FollowSymLinks
    
    <IfModule mod_rewrite.c>
    
    RewriteEngine On
    RewriteBase /
    
    # Blog:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([A-Za-z0-9-]+)\.html$ cat.php?pagename=$1 [L]
    RewriteRule ^category(.*)/(.*)(/|\.html)$ cat.php?Start=$1&pagename=$2 [L]
    RewriteRule ^page(.*)\.php$ /item.php?item=$1 [L]
    
    # WordPress:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    </IfModule>
    Code (markup):
     
    krt, Aug 3, 2007 IP