www.webdeveloper.com
Results 1 to 8 of 8

Thread: [RESOLVED] removing .php ext from URL with .htaccess

  1. #1
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293

    resolved [RESOLVED] removing .php ext from URL with .htaccess

    I want to remove my .php ext and i have the script that works in my ht access. I think...

    But I think since I built my navbar in php its wont find the page when I remove the .php from the a href tags.

    if someone could help I would appreciate it.

    I have a var set on the top of each page so the php navbar knows which page is active.

    this is my nav bar
    Code:
     <ul>
    <?php if ($page == 'home') { ?><li class="active"><a href="index.php" class="active">Home</a></li>
    <?php } else { ?><li><a href="index.php">Home</a><?php } ?>
    
    <?php if ($page == 'services') { ?><li class="active"><a href="services.php" class="active">Services</a></li>
    <?php } else { ?><li><a href="services.php">Services</a><?php } ?>
    
    <?php if ($page == 'projects') { ?><li class="active"><a href="projects.php" class="active">Projects</a></li>
    <?php } else { ?><li><a href="projects.php">Projects</a><?php } ?>
    
    <?php if ($page == 'contacts') { ?><li class="active"><a href="contacts.php" class="active">Contact</a></li>
    <?php } else { ?><li><a href="contacts.php">Contact</a><?php } ?>
    </ul>

    this is my .htaccess file

    Code:
      #RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ $1.php [QSA,L]

  2. #2
    Join Date
    May 2004
    Location
    FL
    Posts
    3,453
    This tutorial should be able to help you: http://sicanstudios.com/post/how-to-...with-htaccess/

    If you want more, Google has plenty of others.
    Lee

    ""Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."" -- Sir Winston Churchill

  3. #3
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    thanks bro ill check it out

  4. #4
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    thanks you solved my issue... next issue... how can i change index to show up as home?

  5. #5
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293

    answer to my question

    this is the code to do all the things i mentioned in my post.

    all this is done in the htaccess file and you must makes sure if you take off the file extentions you also take them off in your links or nav as well.

    .htaccess for removing file extensions and for making the home.php page the default load page instead of index.

    also this is my first time making a 404 page so if someone could check it out and let me know if it looks ok I would appreciate it.

    www.nichodiaz.com

    Code:
       #404 page
    ErrorDocument 404 /404.html
    
    DirectoryIndex home.php index.html index.htm index.php
    
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^\.]+)$ $1.php [NC,L]

  6. #6
    Join Date
    May 2013
    Location
    Kansas City
    Posts
    21
    Quote Originally Posted by Nicholas Diaz View Post
    thanks you solved my issue... next issue... how can i change index to show up as home?
    Do you mean redirecting it to /home instead of / as the root path for your website?

  7. #7
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    I meant both. I took away all the extentions. Then change it to look for home instead of index first

  8. #8
    Join Date
    Feb 2013
    Posts
    17
    And you can also find a practical example here:
    Article Manager with Direct Links Using htaccess

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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



Recent Articles