Mod_Rewrite help

Discussion in 'Apache' started by PhilipB, Feb 12, 2005.

  1. #1
    RewriteEngine On
    RewriteRule ^forums.* /index.php
    
    
    RewriteRule ^viewforum([0-9]*)-([0-9]*)-([0-9]*).* /viewforum.php?f=$1&topicdays=$2&start=$3
    RewriteRule ^mforum([0-9]*).* /viewforum.php?f=$1&mark=topic
    RewriteRule ^forum([0-9]*).* /viewforum.php?f=$1
    
    RewriteRule ^ptopic([0-9]*).* /viewtopic.php?t=$1&view=previous
    RewriteRule ^ntopic([0-9]*).* /viewtopic.php?t=$1&view=next
    RewriteRule ^newtopic([0-9]*).* /viewtopic.php?t=$1&view=newest
    RewriteRule ^ftopic([0-9]*)-([0-9]*)-([a-zA-Z]*)-([0-9]*).* /viewtopic.php?t=$1&postdays=$2&postorder=$3&start=$4
    RewriteRule ^ftopic([0-9]*)-([0-9]*)-([0-9]*)-([a-zA-Z]*)-([a-zA-Z]*).* /viewtopic.php?t=$1&start=$2&postdays=$3&postorder=$4&highlight=$5
    RewriteRule ^ftopic([0-9]*)-([0-9]*).* /viewtopic.php?t=$1&start=$2
    RewriteRule ^ftopic([0-9]*).* /viewtopic.php?t=$1
    RewriteRule ^sutra([0-9]*).* /viewtopic.php?p=$1
    Code (markup):
    This is what I have in my .htaccess file but my forum pages dont work.

    http://www.must-have-software.net/forum/forum2.php

    I re-did the mod_rewrite mod but still does the same thing :confused:
     
    PhilipB, Feb 12, 2005 IP
  2. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #2
    Well the first thing i would say is more precise with the extensions

    try the folowing for each one

    RewriteRule ^ftopic([0-9]*).php$ /viewtopic.php?t=$1 [L]

    I aint no expert but i would say that it should work
     
    piniyini, Feb 12, 2005 IP
  3. PhilipB

    PhilipB Peon

    Messages:
    211
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Tried it, doesn't work :(
     
    PhilipB, Feb 12, 2005 IP
  4. PhilipB

    PhilipB Peon

    Messages:
    211
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I also had to add this to my page header.php in the includes folder

    ob_start();
    function replace_mod_rewrite($s)
    {
    	$urlin = array(
    		"'(?<!/)viewforum.php\?f=([0-9]*)&amp;topicdays=([0-9]*)&amp;start=([0-9]*)'",
    		"'(?<!/)viewforum.php\?f=([0-9]*)&amp;mark=topics'",
    		"'(?<!/)viewforum.php\?f=([0-9]*)'",
    
    		"'(?<!/)viewtopic.php\?t=([0-9]*)&amp;view=previous'",
    		"'(?<!/)viewtopic.php\?t=([0-9]*)&amp;view=next'",
    		"'(?<!/)viewtopic.php\?t=([0-9]*)&amp;view=newest'",
    		"'(?<!/)viewtopic.php\?t=([0-9]*)&amp;postdays=([0-9]*)&amp;postorder=([a-zA-Z]*)&amp;start=([0-9]*)'",		"'(?<!/)viewtopic.php\?t=([0-9]*)&amp;start=([0-9]*)&amp;postdays=([0-9]*)&amp;postorder=([a-zA-Z]*)&amp;highlight=([a-zA-Z0-9]*)'",
    		"'(?<!/)viewtopic.php\?t=([0-9]*)&amp;start=([0-9]*)'",
    		"'(?<!/)viewtopic.php\?t=([0-9]*)'",
    		"'(?<!/)viewtopic.php\?p=([0-9]*)'");
    
    	$urlout = array(
    		"viewforum\\1-\\2-\\3.php",
    		"mforum\\1.php",
    		"forum\\1.php",
    
    		"ptopic\\1.php",
    		"ntopic\\1.php",
    		"newtopic\\1.php",
    		"ftopic\\1-\\2-\\3-\\4.php",
    		"ftopic\\1-\\2-\\3-\\4-\\5.php",
    		"ftopic\\1-\\2.php",
    		"ftopic\\1.php",
    		"sutra\\1.php");
    
    	$s = preg_replace($urlin, $urlout, $s);
    
    	return $s;
    }
    
    Code (markup):
     
    PhilipB, Feb 12, 2005 IP
  5. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #5
    Maybe you should have

    RewriteRule ^ftopic([0-9]*).php$ /forum/viewtopic.php?t=$1 [L]
     
    piniyini, Feb 12, 2005 IP
  6. PhilipB

    PhilipB Peon

    Messages:
    211
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    PhilipB, Feb 12, 2005 IP
  7. PhilipB

    PhilipB Peon

    Messages:
    211
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Bump, anyone know?
     
    PhilipB, Feb 13, 2005 IP
  8. justicewhite

    justicewhite Well-Known Member

    Messages:
    240
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    138
    #8
    Try mod-rewrite*com/forum.

    I've had quite useful feedback and managed to get my mod rewrite problem resolved.

    Good luck...
     
    justicewhite, Feb 15, 2005 IP
  9. iktorn

    iktorn Peon

    Messages:
    66
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Do you get Internal Error 500 ?
     
    iktorn, Feb 16, 2005 IP
  10. nullbit

    nullbit Peon

    Messages:
    489
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Haven't really looked at the regex, but (just guessing), is the forum located in a sub-directory (e.g. somsite.com/forum/), and is the .htaccess file located in a higher directory?

    If so, add:
    
    RewriteBase path/to/forum 
    
    Code (markup):
    Also check your apache error logs from a SSH shell:
    
    cat /var/log/httpd/error_log | tail
    
    Code (markup):
     
    nullbit, Feb 20, 2005 IP