-1

I want to have these rules:

  1. /string-smth matches index.php?param=string-smth
  2. /some-file-with-dashes matches some-file-with-dashes.php
  3. /some-file-with-dashes.php remove .php extension extension
  4. index.php redirects to /

This works on my local machine but not on the server. Are there some options/flags or other things for apache config perhaps that need to be changed to support this?

This is my current .htaccess file

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?param=$1 [QSA,NC,L]

RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=302,L]

On my local machine this works, except for rule #3 (which I have not implemented in .htaccess)

On my server (digital ocean, ubuntu):

1 Answers1

0

So, the part of the answer is in the fix @Martin suggested.

And for the rest:

# remove .php
RewriteCond %{REQUEST_URI} !^/(index|url)\.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=302]

# match .php if exists
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]