htaccess rules html to php - php

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.

Related

URL Rewrite, Virtual Subdomains

Been struggling with this problem for a while now.
We have a basic online app which you can access at say
app.domain.co/signup?user=onlinestore
onlinestore is the username of the account.
We want each user to get their own subdomain that they can use the app from.
In this case the subdomain would be onlinestore.domain.co/signup and it would show them the contents as if they were here: app.domain.co/signup?user=onlinestore.
Now as well as that subdomain mirroring the login pages, when they login I would like for all of the pages inside of the app to be able to use the subdomain as well. Ideally I don't want the user to see the app.domain.co domain at all, just their personalised domain. Theres quite a number of pages inside the app so im not sure if theres a simple way for them all to be accessible from any subdomain (if logged in ofc).
Examples:
onlinestore.domain.co will become app.domain.co/signup?user=onlinestore
onlinestore.domain.co/payments will become app.domain.co/payments?user=onlinestore
onlinestore.domain.co/contact will become app.domain.co/contact?user=onlinestore
Current HTACCESS File (in the wildcard subdomain)
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.co$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+).domain.co
RewriteRule ^$ https://app.domain.co/signup/?user=%1 [L]
We've created a wildcard subdomain but it's not working with https, and it's doing a full redirection as opposed to a rewrite, I'm still on shared hosting so I'm not sure if I might have some restraints due to this.
Is there a simple way to do this? I don’t want the users to see the app.domain path at all, just their custom subdomain path.

Parking domains redirect to landing page wordpress htaccess

I hope everyone doing great, I need help, I use Wordpress last version, I need define for my web site my principal default domain example MyWordpressSite.com and all parking domains go to MyWordpressSite.com/LandingPage/ any way to define all domains in one single line and redirect to the LandingPage? I dont want define domain by domain any way in htaccess or other options?
Thanks in advances for any help!
Regards
Manny
You need a negative pattern, assuming you're on Apache:
RewriteEngine on
#usually need next line though modify if WordPress is running in a subfolder
RewriteBase /
RewriteCond %{HTTP_HOST} !^your\.domain\.tld$
RewriteRule ^ http://your.domain.tld/landing-page/ [L,R=301]
Any request to your non-primary domain will be permanently redirected to that page.

Point subdomain to root without using a subdirectory

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.

htaccess redirect to subfolders resources

I have a problem:
I have to modify an application written in Zend 1 that was deployed to the domain root. now to test it the customer gave me a root subfolder called [domain]/social
When I run it, I have a lot of problem because all paths are like "/resource", but in this case the fiddler show me that the request look for [domain]/resource ad not for [domain]/social/resource.
It happens with script sources, ajax urls, hrefs...all!
Is there a way to fix the problem?
I am not quite familiar with Zend, but is there a main config file that sets the application root folder? (Like joomla) You can modify that if it exists.
Other option would be to preg_match or str_replace all instances of the domain name in the code ( like when moving a Worpress site) but you should definately do that with a sample content not couple hundred pages).
And here is a htaccess snippet as well:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/social/$1 [R=301,L]
Be sure to put the htaccess under the development folder not under the root, oterwise you're facing issues.
I suggest cheking for a config file first. Hope one of this helps!

redirect to different server based on url path

I've made a new website for a client who has an intranet integrated into their old website.
The new website is currently on a different server, but when the domain A records point to the new server, the old site (and intranet) will obviously not be accessible, but I need to keep their intranet active. The path to their intranet is: abc.com/intranet
Is there a way to have URL path direct to the old server? For example:
abc.com - new website loads on new server
abc.com/intranet - old website loads on older server
If it's not possible, I suppose I'm looking at creating a sub-domain on abc.com for the intranet. Any thoughts are appreciated.
You need to use an Apache RewriteRule using mod_rewrite. This can be placed in an .htaccess file on your server’s root or it can be placed directly into your Apache config file.
If you want to redirect example.com to example.com/intranet, then this is the Apache RewriteRule that should work for your needs:
RewriteEngine on
RewriteRule ^(.*)$ /intranet [L,R=301]
This will grab any URL on the site this RewriteRule is placed on & redirect them to /intranet. That /intranet can also be a full URL such as this example below:
RewriteEngine on
RewriteRule ^(.*)$ http://example.com/intranet [L,R=301]
EDIT: Upon rereading your question, I am not 100% sure the answer above works for you as-is. So I think if you are describing how to point one URL path from one server to another, you would do this. This gets placed on the new server:
RewriteEngine on
RewriteRule ^/intranet(.*)$ http://old_example.com/intranet [L,R=301]
That would grab any URL coming from new_example.com/intranet and redirect it to old_example.com/intranet.
ANOTHER EDIT: Since the original poster indicates the server will have the IP fully changed, then a subdomain for the old server is the best way to go. You can’t redirect content on one domain the way you describe if you switch the domains fully to different IP. Both servers need to be active with an active—but different—domain name for what you want to happen.
abc.com/intranet is a path in the virtual file system exposed by your web server, so is not possible to serve the content from different web server. You have 2 options here.
Put a reverse proxy in front of both servers and get the content from server A or B based on the original client request.
As you said, create a subdomain and also redirect /intranet to the new subdomain.
Hope this help!

Categories