I have a site developed in Yii2 on a VPS (Apache 2.4.23) structured like this:
user/app (all the sites files and directories)
user/public_html
In public_html there are links to directories and files such as:
.htaccess (file folder)
admin (file folder)
assets (file folder)
css (file folder)
images (file folder)
index (php file)
The psite has a frontend and backend, the backend is on a subdomain, and frontend on the domain (example.com and admin.example.com)
Frontend load fine both with http and https, whereas the backend does not load the assets (css and images), https on backend redirects to http which I don't want to.
On the error logs I see a bunch (too many to list them all) of errors, like the following samples:
[access_compat:error][pid][client]AH01797:client denied by server
configuration: home/user/app/backend/web/index.php, referer
http://admin.example.com/en/user/index
[access_compat:error][pid][client]AH01797:client denied by server
configuration: home/user/app/backend/web/index.php
[access_compat:error][pid][client]AH01797:client denied by server
configuration: home/user/app/backend/web/en
The htaccess files are the same for frontend and backend like this:
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php [L]
# use index.php as index file
DirectoryIndex index.php
I also tried (suggested by hosting support) with no success.
# use mod_rewrite for pretty URL support
RewriteEngine On
# enable symbolic links
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . index.php [L]
# use index.php as index file
DirectoryIndex index.php
Could you please tell me what's wrong and why frontend works fine, but the backend does not?
In a cpanel setup, subdomains can only be served from directories under public_html.
Related
I feel like this is a rather common request, but I am too confused about .htaccess and couldn't find a solution by Google.
I have a Laravel instance in a subdirectory of the Apache2 htdocs. Now I would like to invisibly redirect all requests from the root domain to this folder (it should be the "root" website). But the tricky thing is, this is not the only folder, there are other folders directly in the htdocs, which should be reached normally. Just the "root" website is not in the root but also in a subfolder. For example:
https://domainA.com should load https://domainA.com/laravel/public (including possible query string or parameters, but invisibly for the user)
https://domainA.com/websiteB should be served as it is
https://domainA.com/websiteC should be served as it is
...
I assume, part of this solution will be to list all the websiteB, websiteC directories in the .htaccess, would it be possible to automate this?
Thanks in advance!
You can put a .htaccess in the folder you want to custom controle but you have to create some filter condition
<IfModule mod_rewrite.c>
RewriteEngine On
## RewriteBase /foo
## conditions to tell what to redirect ie on URI
## RewriteCond %{REQUEST_URI} ^/a-folder/
## not websiteB or websiteC
RewriteCond %{REQUEST_URI} !^/websiteB/
RewriteCond %{REQUEST_URI} !^/websiteC/
## if the file does not exist call index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ my/path/to/a/script.php [L]
</IfModule>
After you have to do something special in script.php for those HTTP calls
You can also rewrite the URI and pass it again to apache but things can be complicated after...
I have read the doc from Yii2 official website to deploy yii2 into share host from this : http://www.yiiframework.com/doc-2.0/guide-tutorial-shared-hosting.html, and about discussion on this : stackoverflow.
So, I decide to use sftp to upload the yii2 folder.
And this is the list of directory in my share host.
access-logs
etc
logs
public_ftp
public_html
ssl
www (this is a link folder to public_html)
You know, because the share host can hold on domains untill 5 domains,
is it possible to upload yii2basic folder into public_html folder ?
So the result like this :
access-logs
etc
logs
public_ftp
public_html
-basic
- bunch of yii folders here
ssl
www (this is a link folder to public_html)
Because now, if I want to access my web, I have to write like this : mydomain.com/basic/public_html/index.php
I need like this :
mydomain.com/index.php
Please guide me.
Yes you can upload it inside the public_html folder but the only problem that I have been facing nowadays with yii2 basic app is the pretty URLs, you can clone or upload entire contents inside the public_html folder, what I did is as follows only the difference is I have a web folder instead of www
directory structure
public_html
assets
commands
config
controller
mail
migrations
models
runtime
tests
vendor
views
web
public_html/.htaccess
<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^/.*
RewriteRule ^(.*)$ web/$1 [L]
RewriteCond %{REQUEST_URI} !^/web/
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ web/index.php
</IfModule>
public_html/web/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
this works but in the URL it shows /web/index.php?r=site/index and as soon as I turn the prettyUrl on in the config file urlManager it would only show default index page and every link I try to open ends up on the home page view although the URL in the address bar is correct and urlManager parses the rules correctly, this is as far as I have gone.
If you don't mind bunch of Yii 2 folders in your root folder just place all basic template folders (except web) and files in the root folder. Then place the content of web folder in the public_html folder.
It should be something like:
access-logs
assets
commands
config
controllers
etc
logs
mail
models
public_ftp
public_html
// here should be the content of web folder of Yii 2 basic app
runtime
ssl
test
views
widgets
I've tryed to follow Yii2 Official Guide to configure Apache-2.4x64 for enablePrettyUrl option. My issue is that I've got 500 Server Error when trying to access localhost/about/web/ in my browser. I've placed .htaccess in my about/web folder.
Here's it's configuration:
# Set document root to be "basic/web"
DocumentRoot "d:/openserver/domains/localhost/about/web"
<Directory "d:/openserver/domains/localhost/about/web">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# ...other settings...
</Directory>
Maybe something wrong with path to about/web? I have this error only on my Windows machine.
Directory and DocumentRoot are not allowed in the .htaccess file, they should be in the apache configuration (or in your VirtualHost config file).
In your case, the .htaccess file is being read, that is why it gives youa error 500 (the file is read but it containt systax errors or bad commands). Therefore, it should be enough to remove the 'DirectoryandDocumentRoot` commands and leave the file just with:
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
Please, make sure that mod_rewrite is enabled in your apache installation.
I created my first online site. I put all my files on the server (I used Wordpress for now) and it's great, but, when I enter my site address (let's say: www.mysite.com) I see only "Under construction". I only see my website after typing: www.mysite.com/index.php.
How can I make www.mysite.com load index.php without needing to enter it in the address bar?
There is probably an index.html file at the root of your public html folder that you need to delete. Once you delete this, your site will load as normal.
Most web servers load .html files before any other files. So if you have index.html and index.php in the root of your public html folder, it will most likely load index.html first.
You also may need to make sure you have an .htaccess file in the root of your public html folder, and that it contains the basic Wordpress code:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
More info on that here.
How can I access a folder placed in the public directory of my default laravel installation. This question is for both - testing as well as live purpose.
While Testing-
I am testing on windows using XAMPP's apache http server. I have placed my app's root folder in the htdocs folder of XAMPP. Thus, when I try to access a folder in public directory, 'localhost/myappname/public/blog' it redirects me to 'localhost/blog'.
I don't want this behavior. I want it to pick up the 'index.php' file present at 'localhost/myappname/public/blog/' location. But it doesn't do so.
While Live-
I have my site live on ubuntu with apache http server. When I try to access 'mysitename.com/blog' in the firefox, it gives me this error -
Firefox has detected that the server is redirecting the request for this
address in a way that will never complete.
I have no hint about what's wrong. I have tried spending two days working with laravel's default .htaccess file(in public folder) and apache httpd.conf but still not able to resolve it. Have searched a lot over stackoverflow and google but still no clue about where I am wrong. Please guide me.
Added:
The content of .htaccess file is -
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
You just need to comment this line in your .htaccess file.
RewriteRule ^(.*)/$ /$1 [L,R=301]
Comment it or strip out from the file. This will solve both your directory /blog issue as well as redirect loop issue.
I used the Alias feature of apache to overcome this problem. I added an alias for '/blog' in my virtual host configuration.