Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-02-2012, 09:02 AM   PM User | #1
john_zakaria
Regular Coder

 
Join Date: Dec 2008
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
john_zakaria can only hope to improve
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
Quote:
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/
john_zakaria is offline   Reply With Quote
Old 07-03-2012, 07:10 AM   PM User | #2
john_zakaria
Regular Coder

 
Join Date: Dec 2008
Posts: 121
Thanks: 0
Thanked 0 Times in 0 Posts
john_zakaria can only hope to improve
[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..
john_zakaria is offline   Reply With Quote
Old 07-03-2012, 10:25 AM   PM User | #3
leslie.jones
New Coder

 
Join Date: Nov 2011
Posts: 88
Thanks: 4
Thanked 26 Times in 26 Posts
leslie.jones is an unknown quantity at this point
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
leslie.jones is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:57 AM.


Advertisement
Log in to turn off these ads.