What's causing this forced redirect? - apache

I do not have root access to the site site.com but I have access to a subdomain me.site.com
I add an index.php (or any file and or folder for that matter) to the root folder (public_html) of this subdomain but everytime I try to go to me.site.com/index.php I get redirected to www.site.com
The .htaccess file in this subdomain is currently blank.
Why might this be happening?
Thanks!

I'm afraid that .htaccess in subdomain folder can't override the .htaccess in root, and at the moment the .htaccess in your root folder is current affecting the subdomain, in which it redirects all visits to the subdomain to root. Imagine that .htaccess from your subdomain folder redirect visits to the directory itself and .htaccess from root also redirects visits to subdomain back to the root itself, that's gonna be a mess.
Well, that's what I think about it in my opinion. Have you tried contacting the one who own root folder to consider about this?

Related

htaccess to redirect a specific path on any subdomains to a specific path on the main domain

I have one .htaccess file (all subdomains point at the same file directory as the main domain, so one .htaccess file would need to accomplish this). What I'm trying to do is this: any current and future subdomains should redirect like so:
sub1.example.com/cart
sub2.example.com/cart
sub3.example.com/cart
unknown_future_subdomain.example.com/cart
Those 4 subdomains and specific /cart path should all redirect to example.com/cart
I have tried different solutions but they caused redirect loops, I think because the sames .htaccess file is loaded on the main domain.

Point subdomain to root of main site on cPanel

I need to point a subdomain (sub.example.com) to the same root as the main site (example.com). So when someone accesses sub.example.com, the same homepage is displayed.
I tried creating the subdomain and pointing it to /public_html instead of /public_html/sub, but if I access sub.example.com I get redirected to sub.example.com/cgi-sys/defaultwebpage.cgi, but if I access sub.example.com/index.php I get the right homepage.
My question is, how to properly point a subdomain to the root of the main site on cPanel?
Any help is very much appreciated.
cPanel redirect to "cgi-sys/defaultwebpage.cgi" when there is not index page present in document root. But as you said sub.example.com/index.php is working so I am not. Add the below lines in .htaccess in public_html folder and give it a try again. Create the .htaccess file if it's not present
DirectoryIndex index.php
Other option is to put a redirect for the subdomain with the domains homepage url
http://docs.cpanel.net/twiki/bin/view/AllDocumentation/CpanelDocs/ReDirects

Where is a 302 temporary redirect code located?

Where would a 302 temporary redirect code located within a website's files? I am struggling to find it and would like to change it to a 301 permanent. I tried .htaccess which I thought would be the most obvious location for it.
Are you trying to redirect the whole site or just one subdirectory?
If the whole site, you'll need to edit the .htaccess file in the root of the site. If a directory, you'll need to create an .htaccess file in that directory that will then control everything below that directory.
This is a simple 302 redirect

Apache cross domain 404

I want to make apache to always open up a signle page for 404 errors from all subdomains.
The problem is that my subdomains are located in subfolders in public_html, and thus have a different root path.
For example the main domain this works quite well:
ErrorDocument 404 /Error/404.html
The Error folder and the main domain are located in public_html respectively.
However for the forum subdomain, located in public_html/forum/ the above root path does not, and it actually looks for public_html/forum/Error/404.html which doesn't exist.
I tried to rewrite rule for the forum folder, but it didn't work out either:
ErrorDocument 404 /../Error/404.html
Seems, it cannot go below the root folder for some reason.
Any ideas how can I refer to the same page from the main and the subdomain alike, without triggering redirects? (eg: http://mysite/Error/404.html would accomplish this, but would also change the url address of the page which I don't want)
Seems, it cannot go below the root folder for some reason.
Because being able to traverse above the document root is a very, very serious security risk. If your webserver gets compromised, people would be able to serve all kinds of files anywhere on your entire server.
If you have access to server config you can setup aliases for the /Error folder. For example, in your forum subdomain's vhost config, you can add:
Alias /Error /path/to/public_html/Error/
This way, when you go to http://forum.yourdomain.com/Error/404.html you'd actually be looking at http://main.yourdomain.com/Error/404.html. Then you can just use:
ErrorDocument 404 /Error/404.html
like normal in your forum subdomain.
But if you don't have access to your server/vhost config, you'll need to use mod_proxy and mod_rewrite. So in the htaccess file in public_html/forum/, add these to the top:
RewriteEngine On
RewriteRule ^Error/(.*)$ http://main.yourdomain.com/Error/$1 [L,P]

Does the recursive .htaccess rule affects subdomains pointing to subdirectories?

Suppose I have a site example.com which points to the root directory of my hosting account and it has a .htaccess file in that directory. Say I have an other domain stuff.example.com which points to the same hosting account, but to a subdirectory of it, not to the root directory, and that subdirectory also has a .htaccess file in it.
If I visit stuff.example.com then will its .htaccess file be affected by the .htaccess settings of the root directory? Or htaccess search starts from the directory where the domain points to, so in this case the htaccess file in the parent directory is not taken into account?
Surprisingly the Apache docs don't ever explicitly answer this, as far as I can tell. But the htaccess tutorial gives the example that if a file is requested from /www/htdocs/example, then Apache looks for the following .htaccess files:
/.htaccess
/www/.htaccess
/www/htdocs/.htaccess
/www/htdocs/example/.htaccess
which presumably leads outside of the DocumentRoot. So it seems that the answer to your question is yes, Apache will read all .htaccess files all the way up to /.
will its .htaccess file be affected by the .htaccess settings of the root directory?
Yes. Where your web root is doesn't matter.