URL Rewriting - hide part of url - .htaccess

I have an url like this one:
http://xxxx.com/cms/
....
http://xxxx.com/cms/about-us/concept/
http://xxxx.com/cms/something/
What i want is hide the cms folder of the url.
So when i type in url http://xxxx.com/ I should be redirected to http://xxxx.com/cms/ but the cms should not be visible.
Any help?

.htaccess file
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/cms/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /cms/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ cms/index.php [L]

The best way to do this is by changing the DocumentRoot in your apache config. In the config file just tack on "/cms" to the DocumentRoot= value and restart apache.

Related

edit htaccess to get inside a folder for rewrite rule

After some help from another question i managed to figure out about .htaccess on my website for Friendly SEO links.
My public_html folder contains those files
index.php
.htaccess
buisnessdetails.php
eventDetails.php
My htaccess so far is this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)\ (.*)$ /$1-$2 [L,R=301]
RewriteCond %{THE_REQUEST} /eventDetails\.php\?id=(.+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /eventDetails.php?id=$1&name=$2 [L]
</IfModule>
So when someone clicks an href which has http://sourtouki.gr/123/abc
the htaccess file goes to the
eventDetails.php file.
But now i want it to change like this
i've edited my public_html folder like this
index.php
events(folder)
2.1 eventDetails.php
buisness(folder)
3.1 buisnessdetails.php
So with these changes i want to do the following thing
Changed the href link to
http://sourtouki.gr/events/123/abc
What changes i must do to the .htaccess file so it can understand that if someone pushes the above link, to go to the eventDetails.php which is inside events folder??
And is it going to be editable so i can add also buisness folder inside that rewrite rule?
You can use something like :
RewriteEngine on
RewriteRule ^(.*)\ (.*)$ /$1-$2 [L,R=301]
RewriteCond %{THE_REQUEST} /events/eventDetails\.php\?id=(.+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /events/%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^events/([^/]+)/([^/]+)/?$ /events/eventDetails.php?id=$1&name=$2 [L]

htaccess redirect http to https for subdirectory

I use this redirect because my website is inside a subfolder (www.domain.com/subfolder/)
So if someone enters the website, it will load like this: http://domain.com
What do I need to add or change in .htaccess so that it redirects automatically to https://domain.com, counting that the website is at domain.com/subfolder
I have tried various redirect codes, but no success. If someone is kind to point me in the right direction or give me a hint.
Thanks for the help.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ subfolder/index.html [L]
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^ https://{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteRule !^subfolder/ subfolder%{REQUEST_URI} [L,NC]

Htaccess URL masking to specific folder

I have the following problem.
I need when people access to www.mydomain.com they really access to www.mydomain.com/folder, and they keep seeing www.mydomain.com in the URL.
How can this be done with de .htaccess of my server?
Thanks
create a .htaccess file in the root of the site with the following code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com/$ [NC]
RewriteCond %{REQUEST_URI} !^../folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9/-_.\s]+)?$ ../folder/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$ [NC]
RewriteRule ^(/)?([a-zA-Z0-9/-_.\s]+)$ ../folder/$2 [L]
that's all you need.
RewriteEngine On
RewriteRule ^(.*)$ /folder/$1 [L]
and try to search before you ask something! there are lots of examples like that.

.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]

Rewrite a sub DIR

I have created a website using IPB which I believe is written in PHP, the URL is the forum at present is
what I would like is the URL to be rewritten to
and when user go to the index for force user to use instead of
any help with be greatly appreciated!
Make sure mod_rewrite is enabled and AllowOverride All is set in your conf file, and put these rules in the .htaccess file in the root of your web directory:
RewriteCond %{HTTP_HOST} !^www
RewriteRule ^(.*)$ http://www.thereviewforum.com/$1 [R]
RewriteCond %{HTTP_HOST} ^thereviewforum
RewriteRule ^forum(.*) http://community.thereviewforum.com$1 [R,L]
EDIT with full .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^thereviewforum.com
RewriteRule ^(.*)$ http://www.thereviewforum.com/$1 [R]
RewriteCond %{HTTP_HOST} ^www.thereviewforum
RewriteRule ^forum/?(.*) http://community.thereviewforum.com/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} !.*\.(jpeg|jpg|gif|png|ico)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Resources