1

I've been trying to hide the php extensions for my site. And I've been able to pull together a few Stackoverflow answers to do just that. However, I just have one last issue where when I POST, the resulting page is showing the .php extension. Can anybody help me on what I need to tweak with my htaccess file to not show .php completely?

# Turn mod_rewrite on
RewriteEngine On

RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^ - [L]

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.example.com/folder/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.example.com/folder/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

Here are the two resources I used from Stackoverflow: How to hide .php extension in .htaccess Website Form do not carry any value when .htaccess File Extension Remover Code is Used

Community
  • 1
  • 1
rworld
  • 13
  • 2

1 Answers1

1

Remove this:

RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^ - [L]

It says:

Dear mod-rewrite

If the request method is POST, whatever the url is, would you please leave it unchanged without doing any rewriting? And would you please not apply any other rules?

Sincerely yours,

etc. etc.

zx81
  • 41,100
  • 9
  • 89
  • 105
  • That causes the issue I was having before, where when I POST it was not redirecting me to the resulting page. After I added that, I was redirected but with ".php" extension showing. – rworld Jun 28 '14 at 10:47
  • Ha, is that right? Let me think about this. And maybe someone else will have a better idea. :) – zx81 Jun 28 '14 at 10:51