Score:1

htaccess syntax issue when moving script to a subfolder

cn flag

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]
Score:0
kz flag
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).

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.