简体   繁体   中英

mod_rewrite rules

I'm trying to get the data after the URL and sent back to the home page. I have had errors in the .htaccess file on one server so I am trying it out on another server.

The links down the side of http://www.newbiemoneymakers.com/bank/ should do directly to http://www.newbiemoneymakers.com/bank/index.php where I then get the title.

My .htaccess file says:

RewriteEngine on
RewriteRule ^http://www.newbiemoneymakers.com/bank/([^/\.]+)/?$ index.php?title=$1 [L]

My index page says:

<?php

    include('includes/functions.php');

    $activeTab = "navhome"; 
    $sent = false;

    $title = (isset($_GET['title']))? mysql_real_escape_string($_GET['title']) : 'Home';    
    $title = str_replace('-',' ', $title);

    if($title != '') {  

        $sql = "SELECT * 
                FROM contents 
                WHERE name LIKE '%$title%'
                LIMIT 1";

        $result = @mysql_query($sql);       
        $row = mysql_fetch_assoc($result);      
    }

    //Set page title
    $pagetitle = (isset($row['name']) && $title != 'Home')? ucwords($row['name']) : "Bank Charges";
?>

But when I click on any of the links (eg http://www.newbiemoneymakers.com/bank/bank-charges-refund/ ) it gives me a 404 page!

Do you know where I am going wrong?

Ian

The pattern of a RewriteRule is just tested agains the URI path (in .htaccess files without the contextual per-directory prefix, so in the root directory without the leading / ).

So this should work:

RewriteRule ^bank/([^/.]+)/?$ bank/index.php?title=$1 [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM