my Website structure is as below:
root
|
|----- .htaccess
|----- public
|
|----- index.php (has all Autoload classes)
|----- application
| ---- controllers
| ---- models etc
Now you may have noticed that i have no index.php/.html in my Root directory and i deliberately did that because i want server to redirect by .htaccess.
I want to achieve that if you as a user visit website say:
http://localhost/testRedirect then it shall point to `public` folder
in the directory without showing public in the URL.
I tried blow solution from SO which claims to work like as i want:
Solution 1 [this simply show Directory structure :( ]
RewriteEngine on
#RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteCond %{HTTP_HOST} ^localhost\$
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/$1
#RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteCond %{HTTP_HOST} ^localhost\$
RewriteRule ^(/)?$ public [L]
Solution 2 [Gives 404 :( ]
RewriteEngine on
RedirectMatch ^/$ /public/
Solution 3 [it redirects but shows public in the URL.
RewriteEngine on
#RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{HTTP_HOST} ^localhost\$
#RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule (.*) http://localhost/testRedirect/$1 [R=301,L]
RewriteRule ^$ public [L]
Please suggest some nice and working htaccess
Gags,
To do this, when running your server, set the document root to the /public folder.
If you are using apache, place this in the virtual host of the website settings.
DocumentRoot "/path/to/project/public"
Ref: https://httpd.apache.org/docs/current/mod/core.html#documentroot
If you are using nginx, Place the following in the server{} of the website settings.
root /path/to/project/public;
Ref: http://nginx.org/en/docs/
For cPanel, Do the following
Log into cPanel.
In the "Domains" section, click the Addon Domains or Subdomains icon, depending on which you'd like to modify.
In the Modify a Domain section at the bottom of the page, click the icon next to the current document root for the domain you wish to modify.
In the popup window, enter the new document root and click Change.
Per the original posters details. BigRock has a tutorial at https://support.bigrock.com/index.php?/Knowledgebase/Article/View/613/9/adding-an-additional-domain-to-your-multi-domain-linux-hosting
Related
I am trying to point the main domain from my host (https://website.com) which right now just goes to public_html to a subfolder in the public_html directory (new.website.com) with the user still seeing https://website.com without changing.
I tried doing what is found in here: https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
And added this code to the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?website.com$
RewriteCond %{REQUEST_URI} !^/new.website.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /new.website.com/$1
RewriteCond %{HTTP_HOST} ^(www.)?website.com$
RewriteRule ^(/)?$ new.website.com/index.php [L]
However 2 things happened incorrectly:
The domain changed to https://new.website.com/404.html
It is giving me a page to proceed with caution since new.website.com does not have a certificate.
(folder name and also a subdomain are both named: new.website.com)
How can i redirect so it still shows https://website.com and go to the wordpress folder?
If I understand your question right, you need to have website.com visible to the public but actually, WordPress is installed on new.website.com
In this case, you need to do Wordpress multisite.
Check: https://codex.wordpress.org/Create_A_Network
I have built my site to live and all my assets are coming back as 404.
The an example link to the assets is 'http://www.mydomain.co.uk/assets/css/normalize.css';
I know all my assets live in /web. so when I add /web to the URL and it works,
'http://www.mydomain.co.uk/{web}/assets/css/normalize.css';
I have added a directory index to my root .htaccess which has helped my site load app.php but this does not seem to work for my assets what am I missing?
//
.htaccess
DirectoryIndex /web/app.php
//
Regards,
To change the document root via .htaccess
add the following to your .htaccess in your server root
RewriteEngine on
RewriteCond %{HTTP_HOST} ^my-domain.co.uk$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.my-domain.co.uk.co.uk$
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]
Explained:
RewriteEngine on
//Enable Rewrites
RewriteCond %{HTTP_HOST} ^my-domain.co.uk$ [NC,OR]
//Regex expression that matches people who find your domain without the www.
RewriteCond %{HTTP_HOST} ^www.my-domain.co.uk.co.uk$
//Regex expression that matches another way to your domain
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]
// from the root file look for the file which you would like to set as your root mine was www/web - and app.php was in there
I am trying to deploy my site online and the .htaccess file which worked perfectly in the localhost seem not be be working the same way on my share hosting domain.
i have a public folder in the root(htdocs) folder which is meant to serve the public files and I used two .htaccess files one in the public directory and the other in the the root(htdocs) folder.
.htaccess for htdocs folder
RewriteCond %{HTTP_HOST} ^mysite\.morehere\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mysite\.morehere\.net$
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule (.*) /public/$1
and that of the public directory
# --- Homepage
RewriteRule ^home$ index.php [NC]
RewriteRule ^home/$ index.php [NC,L]
# --- articles page
RewriteRule ^articles $ articles.php [NC]
RewriteRule ^articles /$ articles.php [NC]
........
My intention is to make the URLs search engine friendly and appealing to users.
Edit: I have made sure mod_rewrite on the production server is turns on but the pages still gets redirected to the not found page.
Like mysite.morehere.net/home/ is redirected to the not found page
Can anyone please help me out to figure out where the problem is.
Check if mod_rewrite is turned on, on your production server
I am new to using multiple sites handling in wordpress. I have a site say, domain.com and sub domains as sub1.domain.com and sub2.domain.com. I have installed WP with multi site option for domain.com and WP installed for sub1.domain.com and sub2.domain.com. Now, i am going to post in the sub domains, and i have to retrieve them in main domain homepage.
How can i do this? i found few plugins with which am unable to achieve my goal. the plugins i have tried wp multisite and a few more.
i found it's little bit tough job to do. can anyone give a step by step procedure to get it done.
and my .htaccess file contains the following code,
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
So, If i change this code, will all of sub domain posts appear on main domain home page?
To display those posts, what i need to add in main domain index page?
Try adding this to an appropriate place in your .htaccess file located in Root folder of your site :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$ [NC]
RewriteRule ^ http://domain.com/ [L,R]
To exclude www subdomain , www.domain.com, add this line before the RewriteRule:
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
I have the following problem. I have a website and a blog in a subdirectory. Both of them are php. I have a .htaccess file in the root folder and another one in the blog folder. I dont' think is relevant, but the blog script is wordpress.
I added a condition in the root .htaccess to skip the requests made for the blog,
rewriteCond %{REQUEST_URI} !^/blog.*
Here it is how it looks. I removed the rest of the file:
Options +FollowSymlinks -MultiViews RewriteEngine on
RewriteBase / RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
// my added line RewriteCond %{REQUEST_URI} !^/blog.*
RewriteCond %{HTTP_HOST} !^www\. RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^(all)/([^/]+)/?$ story.php?title=$2 [L] RewriteRule ^(all)/?$ ?category=$1 [L]
RewriteRule ^/?$ index.php [L] RewriteRule ^advanced-search/?$ advancedsearch.php [L] ...
The problem I have is related to the blog requests. For example sometimes if I try to open an url it works fine, sometimes the home (root page not the blog) is opened. It seems very strange. I think it is related to the host. When the host is to busy the blog page I request is not found so the request is going to the root .htaccess.
I have 2 questions:
how to write a rule and where to
place it to exclude all the requests
for /blog to be rewritten by the root
.htaccess? the blog requests might
look like http: //test.com/blog,
http: //test.com/blog/,
http: //test.com/blog/title,
http: //test.com/blog/title/,
http: //test.com/blog/category/title
does anyone has any idea what happens? Why when I open a blog page it opens the home root page, and if I refresh the page it goes to the blog post page?
Take a look into the mod_rewrite documentation, specifically the -d flag in RewriteCond.
It should be something like this:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule HERE