0

I think there is some problem in my htaccess code but I cannot able to figure out.

What I need is.

1) Remove .php extension from the address like www.domain.com/index instead of www.domain.com/index.php

2) Remove the folder name. My website files store in a folder called public. I want to remove it. www.domain.com/public/index.php to www.domain.com/index

I wrote the below code, please let me know whats wrong in this.

# This will hide the folder name public and the php text
Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+public/([^\s]+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
# if you face any problem than try to uncomment the below line and delete the line after it
RewriteRule (?!^public/)^(.*)$ public/$1 [L,NC]
Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

You can have your rules like this:

# This will hide the folder name public and the php text
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+public/(\S+) [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
# if you face any problem than try to uncomment the below line and delete the line after it
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/public/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643