Jump to content

.php files not working with .htaccess


dc519

Recommended Posts

I’m having some problems using an .htaccess file together with the .php files on my site.

 

Let me supply the details, my domain is seriesthree.com and I’m only working with two files so far, they are index.php and login.php. Each is quite barebones and only contains a line of text stating the name of the file and then a link to the other page.

 

Also, there is no index.htm or index.html in the directory or on my site whatsoever. index.php and login.php are located in the root directory along with the .htaccess file.

 

My goal of this, as of yet small project, is to always strip the trailing file extensions, here, .php., from the files in order to create clean urls. I’m using the following instructions in my .htaccess file:

 

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /dispatcher.php [L]

 

I found this code from a previous post at http://keithdevens.com/weblog/archive/2004/May/24/clean-urls.mod_rewrite.php

 

Note that if you simply go to http://seriesthree.com you won’t see any file extension—in fact you are viewing my index.php page. But then, if you link to login.php, you will see the file extension and if you then link back to index.php, the homepage, you will also see the extension. This is my problem, what am I doing wrong in the .htaccess file that displays the file extension?

 

Below is the code for both index.php and login.php, note that I needed to remove two page breaks from each file--I don't think the phpfreaks posting engine liked this and therefore I removed them below.

 

Index.php:

 

<?php

echo '<html>';

echo '<head>';

echo '<title>index.php</title>';

echo '</head>';

echo '<body>';

echo 'inside index.php';

echo '<a href="login.php">to login.php</a>';

echo '</body>';

echo '</html>';

?>

 

 

 

login.php:

 

<?php

echo '<html>';

echo '<head>';

echo '<title>login.php</title>';

echo '</head>';

echo '<body>';

echo 'inside login.php';

echo '<a href="index.php">back to index.php</a>';

echo '</body>';

echo '</html>';

?>

 

Link to comment
Share on other sites

There are some updates at the bottom of the article:

 

Update (Jul 9, 04): Note that if you use the dispatcher.php mod_rewrite rules above, you should also add dispatcher.php to your DirectoryIndex setting.

 

 

Update (Jul 13, 04): Also see this. You'll probably want to change one of the above lines to "RewriteRule . %{REQUEST_FILENAME}.php%{PATH_INFO} [L]".

 

Maybe one of these will fix your issue.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.