Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts

    htaccess problem (need your advise for my small problem)

    Dear all,

    i want to make my links appears without extensions (www.example.com/about) instead of (www.example.com/about.php)
    i used this code and it works fine
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php

    1- but my problem is that i have a folder name contact and a file with the same name (contact.php)

    when i click on the link www.example.com/contact it opens the folder not the html file

    notice that my website is dynamic and i can not add static links on htaccess files.. i just want to check if there is a folder with the same name just open the original php file not the folder.


    2- also for index.php page on my wampserver when i clicked on this link ( http://localhost/trial/index)
    it goes to http://localhost/index/ which is an error.. i want to go to the direct link without removing /trial/

  • #2
    Regular Coder
    Join Date
    Dec 2008
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [QUOTE=Nataraj;1247477]Refer the apach official sites.


    Regards
    Nataraj


    i dont know what do u mean?
    Last edited by firepages; 07-03-2012 at 09:29 AM.

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    88
    Thanks
    4
    Thanked 26 Times in 26 Posts
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule .* $0.php [L]
    Pretty much does what you want, but there is a fly in the ointment waiting to catch you out - and it's probably what is happening to you.

    If you turn on rewrite logging and debugging in your http.conf file (or virtual host declaration), you should be able to see the issue. You do this by adding the following lines to your virtual host declaration:

    Code:
    RewriteLogLevel 9
    RewriteLog /var/log/rewrite.log
    When you do this you'll probably see your /contact correctly redirects to contact.php with an [INTERNAL_REDIRECT]. BUT......
    Apache2 will, by default, then try and add a trailing slash and run the process again looking for index files. Now as you also have /contact/index.php it will find it and show it. To overcome this, we modify a few options and a complete working example is given below (naturally, you'll need to modify this).

    Code:
    <VirtualHost *:80>
    DocumentRoot /home/user/www/public_html
    ServerName mydomain.whatever
    ServerAlias www.mydomain.whatever
            <Directory />
                    Options FollowSymLinks
                    AllowOverride None
            </Directory>
            <Directory /home/user/www/public_html/>
                    ExpiresActive On
                    ExpiresDefault "now"
                    DirectoryIndex index.html index.php
                    Options -Indexes FollowSymLinks -MultiViews
                    AllowOverride All
                    DirectorySlash Off
                    Order allow,deny
                    allow from all
            </Directory>
    
            ErrorLog /var/log/apache2/error.log
            CustomLog /var/log/apache2/access.log combined
            RewriteLogLevel 9
            RewriteLog /var/log/apache2/rewrite.log
    </VirtualHost>
    I suggest once you are done debugging, set RewriteLogLevel to 3.

    This works on my test box so that if I call http://domain.local/contact I get contact.php. If I call http://domain.local/contact/ (note the trailing slash) I get /contact/index.php served.

    Hope that helps in some small way

    EDIT
    I've just noticed you are using WAMP not LAMP, so it goes without saying you'll need to modify the paths of the log, error & rewrite files.

    You may also be able to do this:

    Code:
    RewriteEngine on
    DirectorySlash Off
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule .* $0.php [L]
    Last edited by leslie.jones; 07-03-2012 at 10:32 AM. Reason: NOTICED WAMP not LAMP


  •  

    Posting Permissions

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