Redirecting URL/main domain without redirecting subdirectories - redirect

Is there a way to redirect the main domain, without redirecting it's subdirectory?
E.g. I want to redirect: https://domain1.com --> https://domain2.com
But I do NOT want to redirect it's subdirectory: https//domain1.com/sub
Is there a way to do this in DirectAdmin, or in .htaccess in main directory on Apache shared server?

Related

HAPROXY, general rule for redirecting a subdomain to a directory

I'm new to HAPROXY's advanced ACLs and I need your help.
I would like to create a redirect based on the subdomain used.
Example :
I have one directory per site on my host.
If someone enters the URL https://test1.test.com, I would like them to be redirected to the test1 directory on the host.
The directory on my host will always be identical to the subdomain.
Example :
https://test2.test.com --> folder /test2
https://test3.test.com --> folder /test3
I would like to create a general rule that redirects to the right folder depending on the subdomain.
I don't know if I was clear enough?
Thank you in advance for your help.

Drupal 8 Internal Redirect

How would I go about implementing an internal dynamic redirect in Drupal 8?
For example lets say my url is "/toy" but internally it needs to be routed to "/filters/toys".
Thanks!
You can use module Redirect:
Install and enable module
Go to Configuration > Search and metadata > URL redirects
Click Add redirect, enter old path and new path you want redirect to:
4. Then Save

Will a CNAME redirect subfolders too?

Say I have a webserver data.mydomain.org.
Right now the webserver has an index.html with a redirect to info.anotherdomain.com.
In addition to providing a redirect, the server has other content like an images folder and a documents folder. These have to remain operational.
My DNS is GoDaddy. If I get on GoDaddy and add a CNAME of info.anotherdomain.com to data.mydomain.org , what happens to the subfolder paths? Will the CNAME make the subfolder paths resolve from lets say data.mydomain.org/images/image1.jpg to info.anotherdomain.com/images/image1.jpg? Or would subfolders be unaffected?
My goal is to get rid of the current index.html redirect and also have the page at info.anotherdomain.com come up in the address bar as data.mydomain.org
First of all DNS doesn't redirects it just route. So you will need the CNAME record to could even reach that subdomain.domain.tld.
But the redir, handling of folders and anything else must be performed from the HTTP server side.

"URL not found" error at my localhost setup of TYPO3 website.

I have setup TYPO3 successfully on my local server. But I am having problem when clicking on any menu item: It's showing "url not found on server".
When I type in the URL manually into the browser it shows the page. It's only having problems when redirecting after clicking on a page item at any frontend website page.
That might be related to the domain config or RealURL... or both ;)
Do you use RealURL? Or do you use the standard url config?
If links to sub pages look like index.php?id=12345 you are using the standard config.
My guess is that the local DNS ("hosts file") is not configured correctly.
With the hosts file you can simulate how the web site will appear when it's online, hooked up to a "real/global" DNS. (Not quite, but in a nutshell)
So if you set up Typo3 to be reached under http://www.example.com/ you need to tell your local DNS ("hosts file") to route a request to http://www.example.com/ to your local host e.g. http://127.0.0.1/ . In that case your host file needs an entry like so:
127.0.0.1 http://www.example.com/
What Domain do you enter to reach your web site? Where do the links from the menu link to?
If you wanna know mor about the "hosts file" look here:
http://accs-net.com/hosts/how_to_use_hosts.html
If you can log in into the TYPO3 backend (/typo3/) and can access the frondend through /index.php, but not through the generated menu links, then RewriteRules for mod_rewrite don't apply.
Usually TYPO3's installer should detect this configuration and disable RealURL, which is responsible for generating such nice looking URLs (instead of index.php?id=123). It seems like this failed (or you copied everything afterwards without the .htaccess file?).
Make sure that you have TYPO3's .htaccess file in place in the root directory of your installation. If this is the case, make sure that mod_rewrite is enabled in your Apache config.

.htaccess file disappears in filezilla? how to check if file is present or not?

for some weird reason my CMS is logging out if the address bar does not have www before the full website name. for example, when we enter xyz.com, it takes me to the website but then it wont show as logged in and if i type in www.xyz.com it will find the cookie and show me logged in.
What i want to do is, when user types in xyz.com, i want it to directly (transparent to user) go to www.xyz.com. I want to add that www before xyz.com. I tried adding a .htaccess file in the directory where index.php is present and this is code in htaccess file.
DirectoryIndex index.php
Redirect xyz.com www.xyz.com/index.php
The .htaccess file is disappearing when i transfer it over ftp filezilla.
If you are willing to modify your index.php you could add the following logic to the top of the file:
/*This is a tempory redirection from mysite.com to www.mysite.com*/
if($_SERVER['SERVER_NAME'] == 'mysite.com')
{
$redirect = $_SERVER['REQUEST_URI'];
header( 'Location: http://www.mysite.com'. $redirect ) ;
}
try this in the htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^xyz.com$
RewriteRule ^/?$ "http://www.xyz.com" [R=301,L]
However, your problem sounds like cookie related. Probably the CMS is using a cookie to check the log in status, but the cookie domain param is 'www.xyz.com' instead of '.xyz.com'.
--- edit ---
improved a bit the final line of the code (it is tested and working), but as tcp said, mod_rewrite must be enabled. If you can't enable it, try the code that Lobsterm posted and if you can't do this either, you could try to change the cookie domain param from 'www.xyz.com' to '.xyz.com'
If you want to use rewrites, make sure mod_rewrite is being loaded in your Apache conf file and check that the AllowOverride parameter is either set to All or the just the directives you want to be allowed in .htaccess
Also as aletzo said, you probably want your cookie to cover your whole domain so change the cookie domain from www.example.com to example.com .
Then, it won't matter if user are accessing with a www prefix or within a subdomain.
EDIT: Glad you found the answer you were looking for, but if you need to make filezilla show you .htaccess in the future, Server -> Force showing hidden files