htaccess routing with one domain and couple folders - .htaccess

I have 2 project - 2 different folders but one domain.
Stucture:
--root
--main
--angular5 project with own .htaccess
--blog
--simple html page
I need, when user go to any link, redirect him to folder main with angular project. If user go to link /blog, redirect him to blog folder.
Angular proect .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# not rewrite css, js and images
RewriteCond %{REQUEST_URI} !\.(?:css|js|map|jpe?g|gif|png)$ [NC]
RewriteRule ^(.*)$ /index.html?path=$1 [NC,L,QSA]
My try of root .htaccess
RewriteEngine on
RewriteRule ^(.*)$ main/$1 [L]
RewriteRule ^(.*)/blog/$ blog/$1 [L]

Solved in this way
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# not rewrite css, js and images
RewriteCond %{REQUEST_URI} !\.(?:css|js|map|jpe?g|gif|png)$ [NC]
RewriteRule ^(.*)$ /mobile/index.html?path=$1 [L]
RewriteCond %{HTTP_HOST} ^/blog [NC]
RewriteCond %{REQUEST_URI} !^/blog/.*
RewriteRule ^(.*) /blog/$1 [L]

Related

configure .htaccess to use a subfolder as root and mask the url

I've been trying several solutions in the internet and can't make the redirect voodoo to work.
Setup
My setup is a website build with jekyll, and I want to consume it as mydomain.com/~user.
The folder structure is
~user
- _site
- index.html
- folder1
- index.html
- folder2
- index.html
- other_stuff
Problem
I was able to redirect from mydomain.com/~user to mydomain.com/~user/_site. So, half way through. The problem came when I tried to mask and remove the _site from the URL again. And I hit a wall.
Basically I want to use: mydomain.com/~user and see that URL in the browser, while beeing served the page that lives in mydomain.com/~user/_site/index.html. And same goes for other links
Request See Served
======= ======= =======
mydomain.com/~user mydomain.com/~user mydomain.com/~user/_site/
mydomain.com/~user/folder1 mydomain.com/~user/folder1 mydomain.com/~user/_site/folder1
What I try
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/~user/_site/?
RewriteRule ^(.*)$ /~user/_site/$1
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.com$
RewriteRule !^~user/_site(.*)$ /~user/_site$1 [L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.com$
RewriteRule ^~user/_site(.*)$ /~user$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^mydomain\.com$
RewriteRule !^~user/_site(.*)$ /~user/_site$1 [L]
However, all these
Do not end with the desired hidden URL in the bar
Give an error, as some of the redirects are not allowed in the server
Partial solution
After tweaking the proposed solution, I was able to identify one variation that partially works
RewriteEngine On
RewriteBase /~user
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/_site/? [NC]
RewriteRule ^(.*)$ _site/$1 [L]
Note that in the last two line, i remove the ~user from the regex. This redirects all subfolders and pages, and allows other folders that are in ~user to be accessed.
However, the "home" mydomain.com/~user is the only one that is not redirected. As it exists the RewriteCond %{REQUEST_FILENAME} !-d doesn't allow it to be processed.
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule ^/?$ _site/ [L]
To redirect the home (~user) to mydomain/~user/_site, but it doesn't work. And tried variations of ^/?$ and ^$. But they don't work either.
Ideas?
You should try it this way.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/~user/_site/? [NC]
RewriteRule ^~user/(.*)$ /~user/_site/$1 [L]

CodeIgniter issues

1) I wanted to get rid of the bootstrap (index.php) name in the URL. I've been in YouTube searching and downloading lots of videos related to this, but none of them worked. This is the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !=f
RewriteCond %{REQUEST_FILENAME} !=d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
I tried everything I could get on the Internet.
2) I couldn't load the files in the public folder where I store my JavaScript, CSS and image files. Path: codeigniter/application/.
What I tried:
<link rel="stylesheet" href="<?=base_URL() ?>public/css/default.css />
And the same for JavaScript files.
3) Routing problems(confusion). My default route us the dashboard controller. But I also wanted to create a login route. So I did this:
$route['login'] = 'login';
But this still routes to the default route when I go to localhost/codeigniter/index.php/login.
Try these .htaccess
# -FrontPage-
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
and
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule .* index.php/$0 [PT,L]
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Use this code in .htaccess file and also remove index.php from your config.php file e.g. $config['index_page'] = '';
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

Redirect domain on subfolder to sub-sub folder

I have a website installed on the following folder structure:
mywebsite.com
-/test
--/current
My goal is to have a domain
mywebsite.com/test
with RewriteCond to look into /current subfolder.
Here is what I have so far :
RewriteEngine on
Rewriterule ^$ /test [L]
RewriteCond %{HTTP_HOST} ^(www.)?mywebsite.com$
RewriteCond %{REQUEST_URI} !^/current/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /current/$1
RewriteCond %{HTTP_HOST} ^(www.)?mywebsite.com$
RewriteRule ^(/)?$ current/index.php [L]
But unfortunately this createt redirection issue

Subdomain directed to main domain

I have added a subdomain: support.mysite.com
The support directory is in the root directory. Now, whenever I try to access the subdomain, I I am redirected to the index.php file of the main domain.
For example, I try to access support.mysite.com/index.php and ending up at mysite.com/index.php
I guess it has something to do with the htaccess file for the main domain, which is:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.(.)$ [NC]
RewriteRule ^(.)$ http://%1/$1 [R=301,L]
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]
There is no htaccess file for the subdomain yet.
Any help would be appreciated!

.htaccess Multiple subdirectory rewriting to www-root

I have the following folder structure:
www-root
Backend
Config
Etc
Frontend
Administration
StoreFront
I would like to be able to access the directories from the main url and hiding the subdirectories in between.
So the administrative part I should be able to access like this:
http://localhost/Administration/
The main page which is stored in the subdirectory "StoreFront", I want to be able to access from the root:
http://localhost
This is the code in my .htaccess file so far:
# Store Redirect
RewriteEngine on
RewriteCond %{HTTP_HOST} ^localhost [NC]
RewriteCond %{REQUEST_URI} !^/Frontend/StoreFront
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /Frontend/StoreFront/$1
RewriteCond %{HTTP_HOST} ^localhost [NC]
RewriteRule ^(/)?$ /Frontend/StoreFront/index.php [L]
RewriteCond %{REQUEST_URI} !^/Administration
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /Frontend/Administration/$2
This code however does not work correctly. It rewrites every file except the index.php file to the Administration subdirectory. One side note: php files which are in the backend directory should remain "includable" from the frontend.
Let me tell upfront you that what you're trying to achieve is mission impossible, now let me tell you why. You have this rule:
RewriteRule ^(.*)$ /Frontend/StoreFront/$1
and down further you have:
RewriteRule ^(.*)$ /Frontend/Administration/$2
You cannot have .* going to both the places. You need to distinguish these 2 paths somehow.
It is besides the point that you have other problems also e.g.:
Not using L (LAST) flag wherever needed
Using $2 instead of $1 in 2nd rule
EDIT: Based on your comments:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(Administration(?:/.*|))$ /Frontend/$1 [L,NC]
RewriteCond %{HTTP_HOST} ^localhost [NC]
RewriteRule ^$ /Frontend/StoreFront/index.php [L]
RewriteCond %{HTTP_HOST} ^localhost [NC]
RewriteCond %{REQUEST_URI} !^/Frontend/StoreFront
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /Frontend/StoreFront/$1 [L]

Resources