I have the following scenario:
blog.site.com points to server1
site.com points to server2.
I want blog.site.com to become site.com/blog. So I thought I'll point blog.site.com to server2 and put in a subfolder blog where I can place an .htaccess file doing the 301 redirect. However by creating a blog subdirectory it overrides the /blog/title-goes-here with a blank directory.
My problem is server1 is being decommissioned and so it won't be available to be used for the 301 redirect.
Is there a way I can point blog.site.com to server2to become site.com/blog/title-goes-here without using a blog subdirectory? Or using a blog subdirectory but not interfering with the url?
Please note. This is a wordpress website which the posts from serve1 have been imported. It's important to keep the blog as a part of the site.com website.
Unless I'm missing something, you don't need a redirect - you need rewrite rules.
Have your DNS entries for blog.site.com and site.com point to server2. Then in the .htaccess on server2 add the corresponding rules:
RewriteCond %{HTTP_HOST} ^blog\.site\.com$
RewriteRule (.*) /blog/$1 [L]
Now whether you access site.com or blog.site.com, you'll end up accessing the same server. The rewrite rule will then ensure that requests of type blog.site.com/something actually call site.com/blog/something.
Note that I haven't tested this though.
Related
I have my folders in public_html like this,
/ - root public html for example.com [has wordpress in it]
/a/ - this has another wordpress installed and a.example.com should be pointed to this directory
/b/ - again wordpress for b.example.com
I tried this code,
RewriteEngine On
RewriteCond %{HTTP_HOST} ^a\.example\.com$
RewriteCond %{REQUEST_URI} !^/a/
RewriteRule (.*) /a/$1
but it doesn't work. I use VestaCP control panel and don't want to add site for each subdomain instead have it all under the same root directory.
I also noticed that going to a 404 page like example.com/a/somenotfoundpage will show me the 404 page of the root wordpress installation and not /a/ installation
How can it be fixed inside .htaccess ? /a/ and /b/ are both multi site installation each and / is normal installation
the url for the /a/ and /b/ are set to a.example and b.example in wordpress settings
EDIT
VestaCP is set to redirect *.example.com to example.com. (I have used it as an aliases when adding the site, and visiting a.example.com shows me example.com content without the address changing in the address bar)
In your wp-config.php file, there's a line that says Subdomains and it's set to 'false' right now. Change it to true and your site will flip over.
Now that said... You may want to consider .htaccess redirecting the old URLs to the new ones. But it should work just that easily.
I want to be able to redirect folders and subfolders (all html) to another server with different folders (php)
I have a domain with DNS redirects Cname and A field pointing the domiain (that has not changed) to new website using php.
So, I want to do the following as an example.
On the old server
http://www.domain.co.uk/folder1/subfolder1/page.html
to go to
New server
http://www.domain.co.uk/folder3/
The domain used to point at the htdocs folder on the first server but now using CNAME and an A field it points to the second (new) server
Can I just redirect bulk folders to the new folders?
Hope this makes sense
Richard
You can redirect bulk folders.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.otherdomain.com/$1 [R=301,L]
This is a simple code that redirects ftm domain.com to otherdomain.com. But if you want to change folder1/folder2 to folder3, well.... just think you could you possibly shrink that to a simple rule? I think below 50 pages you better off wiriting 301 redirects line by line. Otherwise, no short way.
I've inherited a PHP site from another developer and can't quite figure out what's going wrong. I'm suspecting some kind of rewrite rule somewhere but Im not sure where to look (or what specifically to look for...)
I've installed MAMP and it is working fine. I've got a couple sites running in the MAMP directory with no problems.
When I drop this site in and try to run the pages, I get pages with no CSS, JavaSCript or images. When I 'right-click' an image and open it in a new tab the image can't be found because the browser tries to go up one level in the directory to the MAMP directory in stead of looking in the site root directory.
Same thing on links to other pages, they all try to go up to the MAMP htdocs directory.
For example in htdocs I have the root folder of my site with the index page: 'htdocs/mysite.com/index.php'
On the page is a link to another page <li class="nav_company">Company
Clicking on 'Company' causes the browser to go up to the htdocs folder and look for the '/company/index.php', which of course doesn't exist.
Where do I go looking for the culprit on this? Is there a term or something I can search the site files for? I'm using dreamweaver and cold utilize the find and replace tool if I just knew what to go looking for...
Edit Here's the (sanitized) .htaccess file in the root folder of the site
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sitename\.com
RewriteRule (.*) http://www.sitename.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.sitename.com/$1 [R=301,L]
Redirect 301 /products/ http://www.sitename.com/plastic-handles/
Redirect 301 /plastic/index.html http://www.sitename.com/plastic/plastic.html
Redirect 301 /applicator/index.html http://www.sitename.com/applicator/applicators.html
Redirect 301 /company/index.html http://www.sitename.com/company/about-us.html
Redirect 301 /contact/index.html http://www.sitename.com/contact/contact-us.html
Redirect 301 /news/index.html http://www.sitename.com/news/news.html
Redirect 301 /trade/index.html http://www.sitename.com/trade/tradeshows.html
Thanks in advance.
It would seem that your assets and links are all pointing to the root so /contact/index.php will look at http://localhost/contact/index.php instead of http://localhost/mysite.com/contact/index.php
Look into setting up a virtual host to point to the new sites directory.
Otherwise it would be a case of changing all the links and assets to the full URL e.g. http://localhost/mysite.com/contact/index.php
Hope this helps
Edit: here is a guide to setting up a virtual host http://sawmac.com/mamp/virtual/
Edit 2: in response to your edit, .htaccess isn't going to make a difference as when you click a link or the server looks for an asset it's going to be looking in htdocs/. It will go no further and therefore will not reach your .htaccess.
Actually I have a domain - domainone.com
I have created a subdomain cname of anoter domain as
abc.domaintwo.com - CNAME as - domainone.com
so that I can use the js and css files e.g domainone.com/js/jquery.js files as abc.domaintwo.com/js/jquery.js
SO Far everything is FINE, no issues at all.
Problem:
I have a custom 404 page for domainone.com and now when that abc.domaintwo.com goes 404 same page appears which i don't want. Any help is appreciated.
Htaccess of domainone.com:
ErrorDocument 404 /404/
All i want is to have different 404 for both.....
Notes: Don't have access to shell for symlinks or alias as I am on shared hosting.
For what you are trying to do, you will need to use PHP. It cannot be done in your .htaccess. The ideal place would be the virtual hosts file, but sounds like you don't have access.
You should separate the web roots apart from each other, and then mod rewrite:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} abc.domaintwo.com$ [NC]
RewriteRule ^(js|css)/(.*) http://www.domain.com/$1/$2 [L,PT]
This should redirect http://abc.domaintwo.com/js/* and css/* to www.domain.com/js and css/
Note: it is untested, but should work if my memory serves correctly.
I have recently assisted in moving a website from a pure development domain to a live site where there used to be a site handled by another CMS system than what we are currently using. Current system is Joomla, but I don't think it matters much for my question.
So with the current site the URLs are rewritten from the standard Joomla format to be stripped of index.php and .html suffix is added in the address, meaning that URLs look like this:
http://example.com/folder/page.html
In the old site handled by another CMS systems the URLs had the following structure:
http://example.com/side.php?id=1
We are a social organisation with many sites linking to us - also quite a few that we are not even aware of - so the problem I need to handle is this: I need to redirect all these dead links on other sites so that they simply get pointed to the root of our site.
Can anyone please explain to me how to make .htaccess redirect as follows:
/side.php?id=* to root of example.com
In this case I mean the * to mean any number as there are naturally alot of pages with different IDs.
It is not of any significance to me if they point at a www. prefix or not.
Thanks in advance for your help, I hope I have not asked a question that's been answered before but my experience with .htaccess is very limited and having searched and tried different solutions didn't do it for me.
In .htaccess in the root folder, add the following:
RewriteEngine on
RewriteCond %{QUERY_STRING} id=\d+
RewriteRule ^side\.php$ http://%{SERVER_NAME}/ [R=301,L,QSD] #Remove the ",QSD" for Apache <2.4.0, or to keep the query string.
The R=301 will tell browsers/search engines that the page has permanently been moved.
A rule like this should work:
RewriteCond %{HTTP_HOST} .*
RewriteCond %{QUERY_STRING} id=\d+
RewriteRule ^side.php http://example.com [L,R=301]
This will redirect externally, with a HTTP 301 response (Moved Permanently)
What you need here is some 301 Moved Permanently responses to let browsers and search engines know that you're moving pages to a new location. Instead of using a mod_rewrite to redirect all requests to this side.php page, I would analyze each page of your old website and determine where all the content has been moved. Armed with this, use the htaccess Rewrite directive to inform browsers of individual pages being moved
Redirect 301 /side.php?id=123 /about_us.html
Redirect 301 /side.php?id=456 /contact_us.html
I recommend this method because it redirects those who navigate to the outdated page to the new page that has similar content to the old one they were requesting instead of just redirecting them all to your home page.