Kimberly Fox
Kimberly Fox

Reputation: 617

htaccess is not working - simple rewrite Rule is doing nothing on my site

I know these rewrite rules questions are all over StackOverflow - and I've read all of them. I've tested my htaccess code on http://htaccess.madewithlove.be/ and it comes back as working. But on my site it doesn't work.

Here's the code(currently on the site under the /new/ folder):

Options +FollowSymLinks

RewriteEngine On 
RewriteBase /new


RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{REQUEST_URI} [^/]$
RewriteRule ^(.*)$ $1.php

Here's the site: http://strattonindustrial.com/new/property/page

I want the /page/ to redirect to /page.php in the background, but show the /page/ in the URL, but it gives me a 404 page, so no redirecting is happening. I'm basically trying to remove the ".php" from the file name and make it SEO friendly.

Additionally, I've called Godaddy and checked to make sure mod_rewrite is loaded and turned on. They can't find anything on their end that isn't working. So it must be something with my code, but FOR THE LIFE OF ME I can't figure it out.

Upvotes: 2

Views: 1373

Answers (2)

Kimberly Fox
Kimberly Fox

Reputation: 617

I finally got it!!!! From this answer on StackOverflow (last answer): godaddy mod_rewrite not working on subfolder

Apparently, with godaddy (maybe others) you have to add:

Options -Multiviews

To the top of the .htaccess page to get it to work. Now it works like a charm.

Upvotes: 1

anubhava
anubhava

Reputation: 784898

Here is the code that you need:

RewriteEngine On
RewriteOptions inherit
Options +FollowSymlinks

RewriteBase /new

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [L]

Upvotes: 2

Related Questions