I have a legacy project on a server where the actual framework is in a folder above the public_html folder. So the directory structure is like this:
domainname.com
app/
framework/
public_html/
index.php
Now I want to place this on our own server. This is an application created by the hosting company. The root folder is default. So now my directory structure is like this:
default/
app/
framework/
public_html/
index.php
Now he's pointing to the default folder instead of the public_html folder. That's the only difference with the old version. So I've added a .htaccess file to the root folder default. The content of this file is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public_html/$1 [QSA,L]
</IfModule>
In my public_html folder I have a .htaccess file like this:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule . index.php [QSA,NS]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule . /index.php [L,QSA,NS]
So when I go to my website it works. But when I click on a link I get: http://domainname.com/public_html/theclickedpage/.
But I don't want the public_html in my url. How can I fix this?
You may want to search for a way to make a virtual host. I know some of my webhost let me configure the vhost through my admin page. It will let your server consider the url without including the specified folder, but back in the stage it performs needed redirection.
You applied correct rule ,
but the problem is link for the solution of this issue you have to
remove public_html from
your all links and it will automatically redirect to your required
path without public_html.
Related
I followed this tutorial to make a simple API with PHP. It works perfect on my computer. I added some other php files to the source folder and I added a composer package (Firebase/JWT) to the project, so a vendor folder and a couple composer files were created. Now the project folder looks like this:
/
- /plublic
-- .htaccess
-- index.php // requires src/functions.php
- /src
-- connection.php
-- functions.php // requires other src/.php files and JWT from composer
-- panel.php
-- responses.php
- /vendor
-- /composer // and files
-- /firebase // and files
-- autoload.php
.htaccess
composer.json
composer.lock
I uploaded this to my cpanel hosting (at api/) using a subdomain (api.mydomain.com). I made the subdomain with cpanel and first set the root folder to api/public but it didn't work (500 error). Then I tried pointing the subdomain to api/ but that didn't work either. What can I do? I think the problem is in the .htaccess files.
#root .htaccess
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
#/public .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
I don't know much about .htaccess or composer, so I didn't move anything of that. Thanks.
It's pretty obvious why it does not work. Look at your rules:
#root .htaccess
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
The first Rule in your .htaccess file rewrites any request of the root, e.g. www.example.com or api.example.com/ to a subfolder /public.
The second Rule complements this and rewrites any other request to the subdirectory /public, e.g. api.example.com/test to api.example.com/public/test
So, effectively, one of these two rules will always fire.
Since you have set the root of api.example.com already to /public it cannot find a /public/public subfolder; thus, you get an error 500.
To resolve this, you could try to remove both rules in the root .htaccess or you can set the root of /api not to the subfolder.
The public/.htaccess file has a typical single entry point configuration and should be fine.
Always use a fresh browser in incognito mode to test the changes.
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 moved WordPress into sub-folder named /site but the URL now shows http://www.example.com/site. I want it to show without the /site/ subdirectory.
Here's my current .htaccess code
RewriteEngine On
RewriteBase /site/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
How do I remove the physical subdirectory from the visible URL?
I advice you against messing up the contents of the .htaccess file. Revert the changes that you've made to this file and follow the simple procedue.
Login to the admin dashboard.
Go to Settings > General
In the WordPress Address (URL) field type http://www.example.com/site
In the Site Address (URL) field type http://www.example.com
Save the changes and you should be good to go.
According to Giving WordPress Its Own Directory in the Codex, this is what you need (works for me).
Create a .htaccess file in root folder, and put this content inside (just change example.com and my_subdir):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/my_subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ my_subdir/index.php [L]
</IfModule>
There you will also find instructions to do it by changing the URL in the General Settings, which also requires you to copy .htaccess and index.php, and then edit this last. The first method seems easier.
Try following steps:-
1)Create the new location for the core WordPress files to be stored (we will use /wordpress in our examples). (On linux, use mkdir wordpress from your www directory. You'll probably want to use "chown apache:apache" on the wordpress directory you created.)
2) Go to the General panel.
3) In the box for WordPress address (URL): change the address to the new location of your main WordPress core files. Example: http://example.com/wordpress
4) In the box for Site address (URL): change the address to the root directory's URL. Example: http://example.com
5) Move your WordPress core files to the new location (WordPress address).
6) Copy (NOT MOVE!) the index.php and .htaccess files from the WordPress directory into the root directory of your site (Blog address). The .htaccess file is invisible, so you may have to set your FTP client to show hidden files. If you are not using pretty permalinks, then you may not have a .htaccess file. If you are running WordPress on a Windows (IIS) server and are using pretty permalinks, you'll have a web.config rather than a .htaccess file in your WordPress directory. For the index.php file the instructions remain the same, copy (don't move) the index.php file to your root directory. The web.config file, must be treated differently than the .htaccess file so you must MOVE (DON'T COPY) the web.config file to your root directory.
7) go to index.php.... Change the following and save the file. Change the line that says:
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
to the following, using your directory name for the WordPress core files:
require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );
I have hosted my new website here http://cvspforcomval.site90.net/ which is a free hosting site. The problem is that I can't see the pictures in my slide, and when I enter to the navigation links I get an error.
I have changed the default webroot/index.php to:
if (!defined('ROOT')) {
define('ROOT', DS.'home'.DS.'a3503999');
}
if (!defined('APP_DIR')) {
define('APP_DIR', 'app');
and my directory goes like this
/root/
public_html/ <---webroot
app/
lib/
I'm just wondering if using the free hosting site affects the error. Or I just missed something out.
<---EDITED Added below--->
In my shared hosting site. I have setup folder in this way
/app
/public_html <---webrooot
/lib
I have the default htaccess in my public_html which is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
My suspicious is that i need to change my .htaccess. I haven't solved it yet
i am getting page not found error which is due to the anchors. You are not using proper ctp links.You have to create the anchors as
$this->Html->link(__'My Page',array('controller'=>'Home','action'=>'name_of_action'));
I want to move all my web site files (even including index.php) into a subdirectory (for exp: "abc")
For example
BEFORE:
public_html
index.php
a.file
directory
an.other.file
...
AFTER:
public_html
abc_directory
index.php
a.file
directory
an.other.file
...
I want everything to work, as it was before, but i don't want to make any redirections (visible).
People should enter "http://myexmaplesite.com/directory/an.other.file/" and by .htaccess apache serve them "http://myexmaplesite.com/abc_directory/directory/an.other.file/" BUT WITHOUT EXTERNAL REDIRECTS (301,302 etc.)
How could I route all requests to a subdirectory using mod_rewrite?
Try this mod_rewrite rule in your document root:
RewriteEngine on
RewriteRule !^directory/ directory%{REQUEST_URI} [L]
Or in general:
RewriteEngine on
RewriteCond $1 !^directory/
RewriteRule ^/?(.*) directory/$1 [L]
This should be even applicable in server or virtual host configurations.
Something like
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ directory/$1 [L,QSA]