.htaccess redirection to folders and subfolders - .htaccess

I am having issues with htaccess redirections. Following is the issues I am having.
The root folder to which the main domain actually points has the following folder: "example"
example.com is actually internally linked to the path "root/example/" rather than "root/". This is done using the following htaccess code
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/example/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /example/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ example/index.html [L]
The folder "exmaple" has the following subfolders: newexample, newexample_beta
If I go to the URL "example.com/newexample", the URL needs to be internally linked to "root/example/newexample". But the URL redirects me to "example.com/example/newexample/"
could you please let me know what needs to be done

Related

.htaccess file - Redirecting/Masking to hidden directory

I have the below code that we add into the root of a domain name that masks the directory of wordpress to try and keep it hidden. I would rather not have to specify the domain name in the .htaccess file so I can just upload the same file to all the sites. Can someone help suggest how I can alter this to make it work with any domain?
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domainname.com$
RewriteCond %{REQUEST_URI} !^/wordpress-hidden/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wordpress-hidden/$1
RewriteCond %{HTTP_HOST} ^(www.)?domainname.com$
RewriteRule ^(/)?$ wordpress-hidden/index.php [L]

.htaccess to remove index.php and subfolder from URL

I am an .htaccess newbie and am having problems in removing a folder name from my sites URL.
It is currently: www.mydomain.com/engine
I have an expression engine site in a subfolder (named engine) of my hosts html folder. In this folder I have an htaccess document in which I have followed the directions in the expressionengine user guide to remove the index.php? from the URL succesfully, with:
RewriteEngine On
# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I would now like to remove the "engine" referring to the subfolder from the URL too.
I have made numerous attempts going on advice in previous questions but have had no success.
On viewing www.mydomain.com, with any of my attempts I recieve:
Forbidden. You don't have permission to access / on this server.
I thought this could be a permissions problem, but this containing html folder has the same permissions as the "engine" folder which allows access.
Can anybody help with the .htaccess code i require?
yeh, the above rules don't apply to homepage url because it's a directory (doesn't pass the third RewriteCond), use the code below:
RewriteEngine On
# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond $1 ^$
RewriteRule ^(.*)$ /engine/index.php?/ [L]

htaccess - Redirect one folder to another internally

I would like to redirect all no-files and no-directories of one folder to another. The .htaccess should be on root (http://example.com).
Example:
http://example.com/admin/core/file.php - Does not exists. So, redirect (internally) to http://example.com/adminhide/core/file.php
http://example.com/admin/index.php - Exists. So, don't do anything..
I tried to create the code, but I'm having an 500 Internal Server Error:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/admin/$
RewriteRule (.*)$ /adminhide/$1 [L]

mod_rewrite: Redirect sub-domain and folders, but not folder contents

I have assets.domain.com hosting all my images, typefaces, scripts, etc. for a Wordpress installation on the top-level domain. I want to redirect any access to subdomain and folders to top-level domain without affecting the folder contents (lots of file types, so would like to avoid having to list each one as an exemption but if that's my only choice, so be it).
Got close with:
# Enable URL Rewriting
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(images|type|scripts)(/.*|$) - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/robots.txt
RewriteCond %{REQUEST_URI} !images/.* [NC]
RewriteCond %{REQUEST_URI} !type/.* [NC]
RewriteCond %{REQUEST_URI} !scripts/.* [NC]
RewriteRule ^(.*)$ http://www\.domain\.com [L,QSA]
</IfModule>
Thanks to Christopher Brix and mootinator.

.htaccess redirect root to subfolder

I would like mod_rewrite to redirect all requests to non existing files and folders, and all requests to the main folder ("root") to a subfolder. So i've set it up like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC,OR]
RewriteCond %{REQUEST_URI} / [NC]
RewriteRule ^(.*)$ /my/subfolder/$1 [L,QSA]
Unfortunately, it does not work: if i request example.com/public/ it redirects to my processing script (so redirecting to my/subfolder/index.php?app=public ) although the folder "public" exists.
Note that requesting domain.com/ correctly redirects to my/subfolder/index.php
Why is that?
it does not work because your last condition is not matching only the root but any uri that has / in it, which is basically everything. Try the following instead:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /my/subfolder/$1 [L,QSA]
Note that [NC] is not needed as you are not trying to match any alphabets, so "No Case" is not really needed.
Hope it helps.

Resources