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
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
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
I have a perfectly working website working as the root of my webhost (/public_html), but I recently bought a new domain and parked it there too, so I needed a subdir for it (/public_html/newdomaindir).
Now I need to move my entire website to a subfolder (/public_html/website) and I'm having a hard time adapting the .htaccess files.
This was my old working .htaccess file when it was root:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^website.org$
RewriteRule ^/?$ "http\:\/\/www\.website\.org\/" [R=301,L]
#SetEnvIfNoCase Host ^www\.website\.org$ require_auth=true
RewriteCond $1 !^(index\.php|images|css|robots\.txt|js|icons|files|fonts|extplorer)
RewriteRule ^(.+)$ /index.php?/$1[L,QSA]
And now the webhost support suggest that I have this .htaccess file as root, to redirect traffic.
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} website.org$
RewriteCond %{REQUEST_URI} !website/
RewriteRule ^(.*)$ website/$1
But, well... it's not working as expected. My website is broken.
Should I use a different approach, maybe ask the support guys to change the document_root of my website? Should I change anything in the subfolder .htaccess file?
Any help is greatly appreciated. Thanks.
Not my strongest skill, but I would try to modify your previous .htaccess to following form:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^website.org$
RewriteRule ^/?$ "http\:\/\/www\.website\.org\/" [R=301,L]
# not sure what about this
#RewriteCond $1 !^website\/(index\.php|images|css|robots\.txt|js|icons|files|fonts|extplorer)
RewriteRule ^$ website/ [L]
RewriteRule ^(.+)$ website/index.php?/$1[L,QSA]
If this does not work, maybe you will find some clues in this SO answer.
I have a website that I have been working on for a while. All this time I have been editing the live website files on the web server for my development. I finally realized that it was stupid to edit the live site. My "quick" solution is to copy everything from example.com to beta.example.com. I will edit the beta subdomain and when I have a feature to release, I will copy and replace the existing code on the example.com site. Great.
That would be great if I could get it to work. I'm having troubles with my .htaccess files for both domains and URL rewriting.
For my example.com site, I use a .htaccess like so: (there are only a handful of pages on my site)
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301]
RewriteCond %{REQUEST_URI} ^/recent
RewriteRule ^ recent.php [NC,L]
RewriteCond %{REQUEST_URI} ^/about
RewriteRule ^ about.php [NC,L]
RewriteCond %{REQUEST_URI} ^/category/(.*)/(.*)
RewriteRule ^ category.php?id=%1&name=%2 [NC,L]
RewriteCond %{REQUEST_URI} ^/category/(.*)
RewriteRule ^ category.php?id=%1 [NC,L]
The problem with the beta.example.com site is that it always redirects to just regular example.com. It removes the beta subdomain.
What is the proper .htaccess code to get subdomain sites separate from non-subdomains?
You have to configure settings for beta.example.com on your server. Setting like DNS in the domain account and if you are using windows(IIS)/linux(Apache) server then configure it same way as you have configured example.com.
If you are using shared hosting then you must have CPanel for your website. then create new directory through that and point the beta.exapmle.com to that directory.
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