2

I have tried a bunch of different ways now and am getting very frustrated

Options -Indexes Options +MultiViews RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php 

^ Doesn't work at all

Options -Indexes Options +MultiViews <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # Unless directory, remove trailing slash RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/$ http://squeakcode.com/$1 [R=301,L] # Redirect external .php requests to extensionless url RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/ RewriteRule ^(.+)\.php$ http://squeakcode.com/$1 [R=301,L] # Resolve .php file for extensionless php urls RewriteRule ^([^/.]+)$ $1.php [L] </IfModule> 

^Works but goes to a page that doesn't exist.

As mentioned the second code snippet works sort of. The problem is that it removes .php but doesn't pull the .php file so it goes to a not found page.

Am I missing something in my Apache config?

9
  • Where is this .htaccess located and where are your .php files located? Commented Feb 5, 2016 at 19:07
  • My .htaccess file is in my website folder under /var/www which is also where my .php files are. I am thinking I am missing something with the configuration. Commented Feb 5, 2016 at 19:10
  • This stackoverflow.com/questions/8371634/… post may help you. The accepted answer looks to work. Commented Feb 5, 2016 at 19:11
  • Thanks Phil that is actually where I got the code that "sorta" works for me. Commented Feb 5, 2016 at 19:12
  • Did you check your apache error logs so you can see the path it's actually trying to access? That might help you see why it's getting 404. It will show you the path. Also you might try adding / to the rule. /$1.php. I've seen some servers try to use the full absolute path in the URL like (http://domain.com/var/www/file.php) which will give a 404. Commented Feb 5, 2016 at 19:27

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.