1

I have recently purchased a script but this script only works in public_html folder . I need to install it in a subfolder named shop ( public_html/shop/ ) . Now the following .htaccess rules work perfectly when the script is placed in public_html but as soon as I move it to the shop folder , everything stops working . How should I edit the following htaccess rules to make it work in /shop folder ?

Options All -Indexes

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(template/)
RewriteRule . /index.php [L]
Mr Pro
  • 33
  • 3

1 Answers1

0
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(template/)
RewriteRule . /index.php [L]

For this to work in the subdirectory, you need to:

  • Remove the RewriteBase directive entirely. (It's not being used anyway currently.)
  • Remove the slash prefix on the substitution string in the last rule.

Additionally:

  • The parenthesis in the last condition (RewriteCond directive) are superfluous. And this condition should be first, not last (for optimisation).
  • The <IfModule> wrapper is superfluous and should be removed. (Assuming you also have a closing </IfModule> "tag"?)
  • Options +FollowSymLinks is also superfluous given the preceding Options All directive.
  • The RewriteRule pattern in the HTTP to HTTPS redirect (ie. (.*)) does not need to be capturing.

Bringing the above points together, we have:

Options All -Indexes

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_URI} !template/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

This will now work regardless of the directory the script is installed in (root or subdirectory).

MrWhite
  • 12,647
  • 4
  • 29
  • 41