2

I am trying to use .htaccess to rewrite example.php to example.

The code I am using is:

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /example\.php\ HTTP/ [NC]
RewriteRule .+ http://www.example.com/example  [R=301,QSA]

RewriteRule ^example/? /example.php [QSA,L]

The page redirects but shows a 404 - page not found error.

Is there something I am doing wrong? I only want to rewrite this one page and not any other pages within the site

Many Thanks

2
  • mod_rewrite is enabled with php? Commented Jan 31, 2011 at 12:40
  • You can format source code with the {} toolbar button. I've done it for you this time. Welcome to StackOverflow. Commented Jan 31, 2011 at 12:45

3 Answers 3

3
<Location /example>
ForceType application/x-httpd-php
</Location>

and name your file "example" instead of "example.php"

See also the comments at: http://support.modwest.com/content/5/1/en/can-i-have-all-html-pages-parsed-as-php.html?highlight=parse

Sign up to request clarification or add additional context in comments.

1 Comment

While this is a solution, it can make it difficult to edit the file. You can no longer double-click to edit and yuo'll have to instruct your text editor to handle it as PHP every time.
1

if you have only one page to rewrite do not use mod_rewrite, use a simple Alias instruction

Alias /example /my/dir/example.php

Comments

0

I'm using this in apache:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteCond %{SCRIPT_FILENAME} !-d
   RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.