URL not displaying correctly
Results 1 to 5 of 5

Thread: URL not displaying correctly

  1. #1
    Somewhere on Mars chrisguk's Avatar
    Join Date
    Jan 2010
    Location
    Someone tell me?
    Posts
    208

    URL not displaying correctly

    Hi,

    I think my problem is a mixture of MODREWRITE and PHP.

    I have the following .htaccess located in the web root.

    Code:
    RewriteEngine On
    RewriteRule ^about/(([^/]+/)*[^/.]+)$ /about/index.php?p=$1 [L]             
    RewriteRule ^(([^/]+/)*[^/.]+)$ index.php?p=$1 [L]
    The index.php example below is located in the folder "about". Just for your info I also have an index at the web root too serving other files.

    PHP Code:
    <?php 
    $page 
    = isset($_GET['p']) ? $_GET['p'] : '/about/about'

    switch(
    $page) { 
    /*----------------------- PAGES -----------------------------------*/ 

    case 'about/profiles'
    $title 'My Title'
    $keyword 'A few keywords'
    $description 'A good description.'
    break; 

    default:
    $title 'My Title'
    $keyword 'A few keywords'
    $description 'A good description.'
    break; 
    }
    include(
    $_SERVER['DOCUMENT_ROOT']. '/include/header.php');  

    include(
    $_SERVER['DOCUMENT_ROOT']. 'about/'.$page.'.php');

    include(
    $_SERVER['DOCUMENT_ROOT']. "/include/footer.php");

    ?>
    This is my problem:

    When I click on the link http://mysite.co.uk/about/ it throws the errors out below.

    When I click on the link http://mysite.co.uk/about/profiles/ it works fine and for the life of me I cant understand what I have done wrong.

    HTML Code:
    Warning: include(/var/www/mysite/about//about/about.php) [function.include]: failed to open stream: No such file or directory in /var/www/mysite/about/index.php on line 22
    
    Warning: include() [function.include]: Failed opening '/var/www/mysite/about//about/about.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/mysite/about/index.php on line 22
    I am a kinda of newbie so any help/guidance will be gratefully received
    Try not to become a man of success but a man of value

  2. #2
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    1,740
    RewriteRule ^about/(([^/]+/)*[^/.]+)$ /about/index.php?p=$1 [L]

    make the whole regex part optional like so (I also made the slash after about optional, thus you should be able to visit example.com/about and have it work just as well as example.com/about/):


    RewriteRule ^about/?(([^/]+/)*[^/.]+)?$ /about/index.php?p=$1 [L]
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  3. #3
    Somewhere on Mars chrisguk's Avatar
    Join Date
    Jan 2010
    Location
    Someone tell me?
    Posts
    208
    Quote Originally Posted by Derokorian View Post
    RewriteRule ^about/(([^/]+/)*[^/.]+)$ /about/index.php?p=$1 [L]

    make the whole regex part optional like so (I also made the slash after about optional, thus you should be able to visit example.com/about and have it work just as well as example.com/about/):


    RewriteRule ^about/?(([^/]+/)*[^/.]+)?$ /about/index.php?p=$1 [L]
    Hi and thanks for your reply. That nearly fixes it but throws out the following:


    HTML Code:
    Warning: include(/var/www/mysite/about/.php)
    Try not to become a man of success but a man of value

  4. #4
    Senior Member Derokorian's Avatar
    Join Date
    Apr 2011
    Location
    Denver
    Posts
    1,740
    You should check if P is empty. Because p will still be set in the query string but it will be empty when nothing is contained after the / (or the url ends at about)
    Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail
    I'd rather be a comma, then a full stop.
    User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning

  5. #5
    Somewhere on Mars chrisguk's Avatar
    Join Date
    Jan 2010
    Location
    Someone tell me?
    Posts
    208
    Ive realised what the problem is!

    I had my link setup as http://mysite.co.uk/about/

    Instead of http://mysite.co.uk/about/about

    The issue with this of course on a cosmetic level, I only want the users to see about once, if that makes sense?
    Try not to become a man of success but a man of value

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •