Redirect domain to subfolder, from subfolder - .htaccess

My friend's dad asked me to change the design of his website, so he gave me access to his account and I created a sub-folder where I uploaded the new design. The problem is that he has forgotten the password to his control panel and I only have access to the FTP in the sub-folder. I'm trying to redirect the domain (currently going to the root folder) to the sub-folder but since I don't have access to the root folder I'm finding it difficult to do so.
I've already tried a redirect with .htaccess but since I can only upload the file to my sub-folder, it thinks the redirect is to a sub-folder within that folder, instead of the folder inside the root.
TL;DR...
I want to redirect 'mydomain.com' to 'mydomain.com/folder' but only have access to the FTP in 'mydomain.com/folder'.
Thanks in advance!

.htaccess applies to the directory that contains it.
You cannot change this if you have not access to vhost.conf files (what would change the base dir of the site) or to the parent directory’s .htaccess.
You will need to:
Reset your dad’s friend’s password and forget this redirect, changing the existing web files (the cleanest way), or
change the .htaccess file in your parent's dad directory, adding this:
RewriteEngine on
RewriteRule ^/?(.*)$ dir2/$1 [R=301,L,P]
This should redirect the user to dir2, hiding that redirect in the urlbar.
h/t #Alejandro Teixeira Muñoz for the edits!

Related

Exclude a folder in Xenforo

I have installed Xenforo in my public_html in my Cpanel which means my forum is available in site.com
Now I want to add another folder contains my web app and want to access it in site.com/myapp. I created a folder "myapp" in public_htmll beside Xenforo files and now when I enter the URL site.com/myapp it goes to a 404 page of the forum. I need to Xenforo exclude this folder and let the app lunch in this address. How can I do that?
You should move your XenForo installation to a subdirectory - many people use site.com/community as the forum root and either have a separate home page at site.com/ or just redirect the domain root to the /community URL.
This then allows you to have other apps running in other subdirectories like site.com/myapp without issue.
In XenForo 2.x this works fine, If you have enabled full Seo friendly urls from admin panel, Make sure you have proper .htaccess file in place. In you case, I believe you did not upload .htaccess file in public_html folder

If requested directory is doesn't exists in root request it from other directory using .htaccess

What I'm trying to do is, if the requested folder doesn't exists in the current path it should access from the other specified sub directory.
My current Folder structure is follow,
mysite.com/
/index.php
/admin/..
/users/mike
/users/jane
Now what I trying to do is, if user try to access mysite.com/mike request should be access from the users directory mike folder because mike doesn't exists in the root. Also if a user try access mysite.com/users/mike it should redirected to mysite.com/mike.
Include the following line in your mysite.com/.htaccess:
Redirect mysite.com/mike mysite.com/users/mike
You can use .htaccess Generator to help generate htaccess options.

.htaccess redirect subfolder but don't show subfolder in address bar

I have a folder in my public_html directory named landingPages which obviously holds all our Landing Pages.
The problem is all the URLs on Google AdWords etc. are set to the public_html folder, for example:
http://www.example.com/landingPage1.php
Putting all the files in the new landingPages directory was done to clear up the public_html directory and seperate everything a bit but changing all the URLs is something we want to avoid.
I want that if you go to to http://www.example.com/landingPage1.php in the browser that it actually loads whats inside the landingPages folder so it calls http://www.example.com/landingPages/landingPage1.php in the background.
I have tried a few things but can't seem to find a catch all version to determine if whatever is requested in the browser is present in the landingPages folder and if so to re-direct or if this sort of catch all request is at all possible.
If not, I guess I would have to manually create rules for each file I want re-directed including any future created Landing Pages which is what I am trying to avoid here.
put this code in your .htaccess under the website root directory, this will check if the file exists in landingPages folder, if so, it will load the content of that file.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/landingPages/$1 -f [NC]
RewriteRule ^([^/]+)$ /landingPages/$1 [L,QSA]

simple .htaccess rewrite URL to different directory on same server

Ok, I'm clueless here...
I need to rewrite a directory structure and all sub-directories within it to a directory within the same server, but a root that is before the directory.
For example:
http://www.mydomain.com/Themes/default/css/folder
and all directories called upon after folder. Such as folder/sub_folder or folder/afolder/anotherfolder, it needs to include ALL sub-directories within the folder directory.
should be redirected to this:
http://www.mydomain.com
How do I do this via a .htaccess file within the folder path http://www.mydomain.com/Themes/default/css/folder?
Please someone help.
Thanks guys :)
The files within the directory structure still need to be accessible for that structure when called via PHP, but I don't want people being able to browse to http://www.mydomain.com/Themes/default/css/folder and be shown all subdirectories within that folderpath and/or all files. Same thing for all sub-directories that follow that folder path.
I'd like to be able to place the .htaccess file within the http://www.mydomain.com/Themes/default/css/folder directory on the server, but don't know exactly what code to use for this.
ALSO, even more challenging... The domain name can change, so I'd rather not use the domain name within the .htaccess file, instead perhaps use .. or . to go up a directory or a different method of grabbing the domain name within the .htaccess file.
Create a .htaccess file in /Themes/default/css/folder and place these lines there (it requires mod_rewrite):
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ http://%{HTTP_HOST}/ [R=301,L]
It will redirect (301 Permanent Redirect) all requests to a folder to a homepage. If file is requested, it will allow it.
If you want to have it working for folders as well as files then remove the RewriteCond line -- it will redirect ALL requests (even for non-existing URLs) to a homepage.
If you will see "500 Internal Server Error" after creating such file, then it is your server configuration: mod_rewrite may not be enabled or it's directives (RewriteRule, RewriteCond, RewriteEngine) are not allowed to be placed in .htaccess. In any case -- check Apache's error log for exact error message (it will give you the exact reason).
http://www.besthostratings.com/articles/prevent-directory-listing.html
IndexIgnore *

CakePHP htaccess modification to allow vBulletin

I'm looking to set-up a vBulletin install next to a CakePHP install. I was planning on just popping the the vB folder into webroot, but when accessing the folder in my browser, it loses the short URL (i.e. it goes from .com/community to .com/app/webroot/community)
Because of this I wanted to put the vB folder into the root of the directory, next to the app directory, so I can access it directly via .com/community - but the htaccess file is getting in the way, complaining that it can't find the community controller.
So my question is this - what edits do I need to make to the htaccess file for it to allow access to the /community folder directly.
Thank you
Add the following line to your .htaccess file:
RewriteRule ^(community).* - [NC,L]
This will allow direct access to the community folder which is in root directory. Accessing http://localhost/community would be possible after adding this rule.

Resources