Reputation: 571
I am using a htacess file to remove the .php extension from my webpages. However, I have a page called images.php and a directory called images (both in the root).
Therefore when the .php extension is removed from the images webpage, the site redirects to the image directory.
I've tried renaming the images file from image.php to imageone.php and then using a htacess redirect, but the problem persists
Can I overcome this in any way?
# Remove .php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule .* $0.php
#browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]
</IfModule>
Redirect 301 /images.php http://www.thewebsite.com/imagesone.php
Upvotes: 0
Views: 137
Reputation: 786319
Avoid mixing Redirect
with mod_rewrite
and have your rules in this order:
RewriteEngine On
RewriteRule ^/?images\.php$ http://www.thewebsite.com/imagesone.php [L,NC,R=301]
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.+)\.php$ /$1 [L,R=301,NC]
# internally add .php to requests
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
Upvotes: 0
Reputation: 4315
You forget the #
before your comment line browser requests PHP
.
# browser requests PHP
Upvotes: 1