I’m failing in edit a .htaccess file.
I created a complete website in a php slim framework (let’s call it website S).
My client have a wordpress website (let’s call it website W) that will have links toward my website S.
I copied all the files of my website S inside a directory of the root directory of the website W.
My idea is to change the follow htaccess (created by wordpress) to allow public access to the directory without creating any problem to move inside website S.
First .htaccess
RewriteEngine On
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteCond %{QUERY_STRING} !wc-api [NC]
RewriteCond %{HTTP_HOST} ^website.pe$ [OR]
RewriteCond %{HTTP_HOST} ^www.website.pe
RewriteRule ^(.*)$ https://website.pe/$1 [R=301,L,NE]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Then, I guess I could use inside the directory where the website S would be, the typical htaccess that works properly for it.
Edited I added the structure of the website S. The index.php is inside a public directory there.
Second .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteBase /
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
I try different ways but, or get the message
"Forbidden You don’t have permission to access this resource."
Or get inside but the website W stop working.
Any suggestions? Thanks in advance.
2
Answers
Yes MrWhite, I delete in the second .htaccess the
RewriteBase /
and now I can access a simple index.html in the directory where the slim website is that I used for testing.But I can't make the website S to run because inside the website S directory exist a public subdirectory with the index.php, arranged like this:
I am new to htaccess and don't understand how one htaccess overwrite the other one, so if I use something like you told me in my second htaccess only like this
That should work... but still not
In the config you’ve posted you would just need to remove the
RewriteBase /
directive from the second.htaccess
file in the "slim" subdirectory. This is causing requests to your slim website to be routed back through the WordPress site in the document root (which would presumably result in a 404).You shouldn’t need to touch the WordPress
.htaccess
file in the document root. This already allows you to access website S.By default, the
.htaccess
file (or rather, the mod_rewrite directives) in the slim subdirectory is going to completely override the WordPress.htaccess
file in the root.Consequently, you’ll need to repeat the HTTP to HTTPS redirect in the slim subdirectory (with a difference*1), before the existing directives. Presumably, the intention is to also redirect www to non-www? Although your current redirect (in the root
.htaccess
file) is not doing this properly.For example, at the top of your second
.htaccess
file in the slim directory add the following:*1 Note the use of the
REQUEST_URI
variable instead of the$1
backreference as used in the root.htaccess
file. This is necessary when used in the subdirectory, otherwise, the subdirectory will be omitted from the redirected URL.NB: Test first with a 302 (temporary) redirect to avoid caching issues.
UPDATE:
This is a rather important bit of information missing from your initial question. I assume that the
public
subdirectory is not part of the visible URL, in which case your second.htaccess
file in the slim subdirectory (the parent directory ofpublic
) should be something like this instead:The
QSA
flag is not required.You do not need the
<IfModule>
wrapper.