htaccess redirect remove /app/webroot in cakephp - .htaccess

I have an htaccess file that I want to redirect the all pages to the another folder. I am using cakephp for the site, except for this folder which I want to redirect.
"/app/webroot/" is added to the new directory so the url is /app/webroot/new/ instead of just new.
I am placing this htaccess file (below) in the "new" directory and want anything at /app/webroot/new/ to redirect to /new/ and remove the /app/webroot/ This folder is independent of cakephp and thus does not need to be processed by cake.
The code below loops and I am not sure why.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /new/
# If your concerned about direct access to a particular page without the sub-dir
# you will want to add something like this
RewriteCond %{REQUEST_URI} !^/new
RewriteRule (.*) /new/$1 [R=301,L,NC]

You should NOT place the .htaccess file in /new/ but in /app/webroot/new/.

Related

hide the actual name of a file inside a folder using .htaccess file

suppose, I have an index100.php file inside folder1 (eg. folder1/index100.php). Is there any way so that if the user types folder1/index.php, then it will automatically redirect to folder1/index100.php?
How can it be done using .htaccess file?
If you want to show index100.php insted of index.php as your directory handler, you can use DirectoryIndex directive in /folder1htaccess
DirectoryIndex index100.php
This will serve you the /index100.php if you visit http://example.com/folder1
If you actually want to redirect /folder1/index.php to /folder1/index100.php then use the following rule in your /folder1/. htaccess .
RewriteEngine on
RewriteRule ^index\.php$ /folder1/index100.php [L,R]

htaccess rewrite being overwritten

I have the following htaccess file in the root of my site to redirect a directory 'MyDirectory' to another URL (to stop google indexing both sites)
RewriteCond %{HTTP_HOST} ^myurl\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.myurl\.co\.uk$
RewriteRule ^mydirectory\/(.*)$$ "http\:\/\/www\.redirectURL\.com/" [R=301,NC]
I then have another htaccess file in the 'MyDirectory' directory above which handles the URL and query string in a user friendly way:
RewriteRule ^Answers/(.+)$ Answers.php?articleName=$1 [QSA]
However, when i have the ReWriteRule ^Answers... section in my other htaccess it stops the redirect in the root of my site from working.
Any suggestions why the ^Answers/... rewrite is overwritting my redirect to www.redirectURL.com.
Thanks
.htaccess is per directory directive and for any URI path it current directory's .htaccess is processed first. If no .htaccess is found then it starts going 1 level up the directory tree until it finds one. It processes DocumentRoot/.htaccess in the end.
In your case since you have a /MyDirectory/.htaccess therefore all the directives are read from that file only thus overriding all the rules of DocumentRoot/.htaccess.
However you can add this line after RewriteEngine On in /MyDirectory/.htaccess
RewriteOptions inherit
This will process parent .htaccess after completing current one.

.htaccess rewrite from subdirectory

Any help with this would really be appreciated.
I am setting up 301 redirects in a .htaccess file to redirect hundreds of old urls to the latest live pages.
My .htaccess file is currently located in the root of the domain and looks something like this:
RewriteCond %{QUERY_STRING} ^pName=product-one$ [OR]
RewriteCond %{QUERY_STRING} ^pName=product-two$ [OR]
RewriteCond %{QUERY_STRING} ^pName=completely-different-name$
RewriteRule ^catalog/product_info.php$ http://www.mydomain.com/new-product-name-p-123.html? [R=301,L]
While researching for answers on how to bulk redirect to one url using .htaccess, I read that it would wise to change the location of the .htaccess file and place it in the specific directories to which it apply's, so requests to other directories won't even these rules.
So I have placed the .htaccess file in the specific sub directory, which is catalog, but the redirect no longer works. What am I missing here? I want the rules for the urls to be redirected to be placed in the .htaccess file inside the catalog folder so all those rewrite rules wont be loaded each time the root .htaccess is loaded.
I would suggest you change your redirect 301 line to contain the path directly to you catalog folder of OSCommerce.
So instead of using
RewriteRule ^catalog/product_info.php$ http://www.mydomain.com/new-product-name-p-123.html? [R=301,L]
use e.g.:
Redirect 301 /website/catalog http://www.mydomain.com/page2.htm
or
Redirect 301 /catalog http://www.mydomain.com/page2.htm
Option 1) is if your catalog is located at http://youdDomain.com/website/catalog/ .
If it is located at http://youdDomain.com/website/aaa/catalog/ you would use:
Redirect 301 /website/aaa/catalog http://www.mydomain.com/page2.htm
I tested this in my own webserver - hope it helps.
When you put the .htaccess in a subdirectory, you must adjust the RewriteRule pattern accordingly. mod_rewrite strips the directory prefix, where the .htaccess file is located, see RewriteRule - What is matched?.
You must change the rule to
RewriteRule ^product_info.php$ ...
If you have lots of URL paths to rewrite, you might also want to look into RewriteMap.

How to redirect any folders within a subdirectory to a specific file using htaccess?

I want to redirect any folder to a specific php file with the folder name as variable using htaccess, for example:
www.domain.com/subdirectory/folder1 redirects to www.domain.com/subdirectory/file.php?id=folder1
www.domain.com/subdirectory/folder2 redirects to www.domain.com/subdirectory/file.php?id=folder2
This should work if the folders have "/" at their end, for example,
www.domain.com/subdirectory/folder3/ redirects to www.domain.com/subdirectory/file.php?id=folder3
It will be better if I can put the .htaccess file in the subdirectory and get redirect rule according to it.
I created a .htaccess file with the following code while putting the file in the subdirectory:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)$ file.php?id=$1
but it does not work.
RewriteRule ^folder(.*)$ file.php?id=$1
use these i am not tested but it will be work.

.htaccess redirecting requests to the same folder

I want to use .htaccessto redirect different requests to the same folder.
E.g.:
domain.de/ordner1/fileX.html
domain.de/en/folder1/fileX.html
domain.de/it/casella1/fileX.html
So whenever something is requested out of /ordner1/, /folder1/ or /casella1/ I want .htaccess to fetch the requested file out of a specific directory like domain.de/all/fileX.html.
I want to prevent duplicate content but also keep the foldernames in the selected language.
Could you help me solve this problem?
Try adding the following to the .htaccess file in the root directory of your site.
RewriteEngine on
RewriteBase /
#skip css, js etc
RewriteCond %{REQUEST_URI} !\.(css|js)[NC]
#if request to ordner or folder1 or casella1, serve the file from all/
RewriteRule ^(ordner1|en/folder1|it/casella1)/(.+)$ all/$2 [L,NC]
In your docroot/.htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^(ordner1/|en/folder1/|it/casella1/)(.*$) all/$2 [L]
You would need to add extra names to map other translation equivalents.

Resources