.htaccess redirecting requests to the same folder - .htaccess

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.

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]

Changing stylesheet url using .htaccess 2

I have very specific question, I want to solve it using .htaccess and mod_rewrite, I want to make rule in .htaccess file using mod_rewrite, so when somebody visit my site ex.
mysite.com , mysite.com/css/style.css file should be read from other location mysite.com/version1/css/style.css, if I say it otherwise, style.css should not be "picked up" from root folder, but sub-folder.
Try adding this to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$ [NC]
RewriteRule ^css/(.*)\.css$ /version1/css/$1.css [L]

.htaccess rule stacking and 404 redirect

The user requests a PNG image, say: http://server/myfolder/subfolder/1234.png. If that .png doesn't exist, then I want to show instead a .gif in the same folder of the same name except for the .gif extension, which should exist.
Another addition is that we recently changed the directory structure so the URL that I need to check may have changed. For example, the URL above should be able to be reached by requesting either directly as http:// server/myfolder/subfolder/1234.pngor by http://server/oldfolder/1234.png. The change in the directory structure can be expressed as:
RewriteRule oldfolder/(.*) myfolder/subfolder/$1 [L,QSA]
In both directories, I need to check if the file exists, and use a different image instead if necessary. Any help would be greatly appreciated.
Try adding the following to the .htaccess file in the root directory of your site.
It should work with your changed file structure too.
RewriteEngine on
RewriteBase /
#if the file does not exist
RewriteCond %{REQUEST_FILENAME} !-f
#and is in any of these folders: /myfolder/subfolder or /folder1 or /folder2
RewriteCond %{REQUEST_URI} ^/(myfolder/subfolder|folder1|folder2)/ [NC]
#and its a png, then try to serve the gif instead
RewriteRule ^(.+)\.png$ $1.gif [L,NC]

htaccess redirect remove /app/webroot in cakephp

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

Cannot remove index.php from my urls in Codeigniter

I am using codeigniter and when I set up the website I added necessary code in my .htaccess file to remove index.php (default) from my urls. I just happened to replace my public_html folder from a back up file of my website. Since I did that, I cannot get any of the links on home page to work unless insert index.php in the url between the domain name and the rest of the url as in http://www.obsia.com/index.php/contact/ instead of http://www.obsia.com/contact/ and it works. So, in my config file within the application folder, I changed
$config['index_page'] = "";
to
$config['index_page'] = "index.php";
and all the links seem to work now. But how do I remove index.php from the URLs.
Here is what my .htaccess code looks like:
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|public|user_guide|robots\.txt|css)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Can anyone point me in the right direction. It will much appreciated.
Regards,
G
What yo want to do can be done this way:
RewriteEngine on
RewriteBase /
# Static content. Rewrite to - (don't change) and mark as last rule.
RewriteRule !^(index\.php|public|user_guide|robots\.txt|css) - [L]
# Do the rewrite.
RewriteRule ^(.*)$ /index.php?/$1 [L]
However, a slightly better way of doing that is this:
RewriteEngine on
RewriteBase /
# Only do the rewrite under the condition that the requested URL isn't a (real) file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?/$1 [L]
there are so many ht access files... In my case i was editing the wrong file... u should edit the file that is inside the project.. for example i work on code igniter and project name was test , so inside test folder i had a htaccess file and inside my application folder ie test/application there was another htaccess file.. i was editing the access file inside the application folder, but i had to edit the file in test folder not test/application/.htaccess.... hope sum 1 finds this useful.. cos i spent half a day to figure this out :(
Cheers
ksp

Resources