When typing my website's URL with a subfolder, why does the subfolder name get combined with the URL name? - apache

For some reason, when I type in my website's short-form URL (without WWW), any subfolders get smushed into the end of the domain name, and I end up getting my ISP's error page.
hudsons.network/weather as an example
But entering my website's URL with WWW works just fine.
www.hudsons.network/weather
At the same time, just typing in hudsons.network redirects to www.hudsons.network, the way I had configured it in Apache.
Here's my configuration:
I have two Virtual Hosts, one for hudsons.network (the default) and another for www.hudsons.network (my own)
In the configuration file for the default host, I have this line:
Redirect permanent / http://www.hudsons.network
I've seen similar behavior on Safari, Opera, and Internet Explorer, and I think it has to do with my website's redirects. Why is this happening, and what rules do I need so that my site redirects the way I expect?

I've found the answer here. I also deleted the RewriteBase line because my config file is in /etc/apache2/sites-available. Works like a charm!

Related

IIS 8.5 Redirecting

I have a basic project running on IIS 8.5
sites
-> test.domain.com
--->virtualPath
----->index.html
On the browser when enter https://test.domain.com/virtualpath, it is return 301 (redirect) to test.domain.com/virtualpath/
I don't have any URL Rewrites in IIS configuration. Just trying to figure out why it is redirecting to test.domain.com/virtualpath/
How can avoid this 301 redirect?
The short answer is that IIS doesn't handle extensionless URLs very well. URLs are processed based on the file extension, otherwise it's presumed to be a directory you're looking to get served. The normal convention however is to omit the index.html file.
But most services like IIS take that for granted, and if nothing is specified, it will lookup if there's a /index.html.
Lets take a simple example:
google.com
In reality what's being served to you is:
google.com/index.html
Lets take your request as an example https://test.domain.com/virtualpath
test.domain.com
- virtualPath/
- index.html
As you can see, you're essentially trying to get a directory rather than a specific file. It's up to IIS to try to find and understand that you want a file instead of a directory now. That's why you're getting a 301. It's redirecting you to the /index.html file.

Web browsers removing slash in URL

I have a URL (http://www.example.com/). Whenever me, a user, or a bot(search indexers) enter (http://www.example.com/Folder) the domain automatically redirects to (http://www.example.comFolder). All browsers are removing this slash. This also applies to files and subfolders, the slash after .com is removed and the user is redirected to their default DNS search site.
What can I configure, either with DNS or on my server, to prevent the root slash from disappearing?
My Server is configured:
Ubuntu 14.04 VPS
Running Apache, PHP, MySQL
Domain purchased through NameCheap
Site uses CloudFlare DNS
Any ideas would be greatly appreciated
Check the configuration file in /etc/apache2/sites-available/your_site_name.conf. If you have a Redirect "/" "https://your_site_name.whatever", it might be that the redirect is stripping the forward slash from the URL there. If this is the problem, just add a trailing forward slash to the redirect url. This is what happened to me. I could navigate to the index.php but not to the info.php file I had placed at the root when I set up the virtual host.
Scour your Apache configuration for Redirect* or Rewrite* rules; also all .htaccess files in the DocumentRoot. If that doesn't turn up anything, examine the PHP application you're using.

Mapping folder to different folder on the same Apache Server

I have My old domain on my server myexample.com with folder name "myexample" and a have different domain mymaindomain.com, What i am looking is whenever user opens mymaindomain.com/contest it opens the site that is in "myexample" folder and still keep the url in address bar mymaindomain.com/contest/whatever.xxx using htaccess or httpd on apache server.
Put
Alias /contest /public_html/myexample
in the virtual host definition for myexample.com. Note though, that this may cause links in your content to be wrong if they expect to be located at / instead of at /contest.

Unwanted Apache redirect behavior

My Apache installation on my Ubuntu 12.04 server redirects requests addressed to:
http://87.73.120.126
to
http://90.184.18.96/joomla/index.php/jomsocial
The address 87.73.120.126 is my servers current IP-address. The address 90.184.18.96 was the one it had half a year ago.
My question is: why does it do this? and how do I make it stop?
Half a year ago I wanted to make requests to http://90.184.18.96 redirect to http://90.184.18.96/joomla/index.php/jomsocial
I did this by adding this line:
RedirectMatch permanent ^/$ http://90.184.18.96/joomla/index.php/jomsocial
to the file /etc/apache2/apache2.conf
A couple of days ago I tried to solve the current redirect problem by changing the line above to:
RedirectMatch permanent ^/$ http://127.0.0.1/joomla/index.php/jomsocial
and rebooting the server. This did not solve the problem!
Then I tried to do a global file search for the string 90.184.18.96 using this command:
sudo grep 90.184.18.96 / -irn --exclude-dir={bin,lib64,opt,sbin,tmp,boot,lost+found,proc,selinux,dev,media,root,srv,lib,mnt,run,sys,mail,log,doc,src,recovery-mode} --color
this search revealed a couple of outdated CRON-entries that I also fixed to use 127.0.0.1 instead. This didn't help either. So, where could the string '90.184.18.96' be residing? I guess it must be somewhere in order for anything to redirect to that address.
This server runs Joomla from the path /var/www/joomla/. As this path is not excluded by my grep-search any redirection emerging from Joomla should be revealed by the grep-search.
Two considerations:
Redirecting to 127.0.0.1 will redirect to the user's machine, not your server. If you're only spanning one server, you should not include your server's IP (it's not nice to access a site with a domain i.e. www.your-domain.com and be redirected to an ip address). So the rule should use variables for the host: %{HTTP_HOST} and %{REQUEST_URI} for host and path.
Besides httpd.conf you may also have redirect rules in your .htaccess which resides in the webserver root: and it's a hidden file so it could have been skipped by your grep, have a look into that as well. Beware the syntax of .htaccess and httpd.conf is slightly different.
You're achieving two things with that redirect: point to an installation which is off-root (/joomla) and setting a different homepage. Setting the homepage in Joomla is as easy as marking its menu item with a star in the menu item editor, so you might not need the second part.

replacing domain names using .htaccess

I have a new website as http://abc.com/case_studies/casstudy20/.
I have an old website as http://xyz.com/clients/home.php?client=myclient
There are loads of case studies and stories under old domain that is xyz.com. Now that I am using abc.com is it possible to replace the URL, so it shows abc.com but access the code from the same old place.
meaning when my users goes to old site instead of xyz.com. It should say http://abc.com/clients/home.php?client=myclient. But runs from the same old xyz.com.
Is it possible to do it using htaccess.
Sort of. You can redirect all the traffic from xyz.com to the proper path on abc.com but this requires you to maintain control of both domains.
If you can, it's actually better to put this in the virtual host config for xyz.com then you don't need a complete configuration at all. Assuming you have permissions it will work in .htaccess as well though.
RedirectMatch ^(.*)$ http://www.abc.com$1
If you can keep control of both domains then you are looking for a http 301 redirect. You can do that by adding the following line to your htaccess file to redirect an entire website. Without control of your original domain it's impossible for your old xyz.com website to be routed to the appropriate server so your htaccess file will never have anything to redirect.
redirect 301 / http://abc.com/