I have many files in directory /full/
that's why I would like to spread files to /full1/, /full2/, /full3/ folders on server but to save original URL like
http://my-domain.com/full/article-with-text
to determine which files are where to put I'd like to define it on the URL mask like
^/full/a$ from folder /full1/
^/full/b$ from folder /full2/
tell me please how to build correct .htaccess ?
Try this
RewriteRule ^full/a(.+)?/?$ http://my-domain.com/full1/a$1 [NC,L]
RewriteRule ^full/b(.+)?/?$ http://my-domain.com/full2/b$1 [NC,L]
RewriteRule ^full/c(.+)?/?$ http://my-domain.com/full3/c$1 [NC,L]
...
RewriteRule ^full/z(.+)?/?$ http://my-domain.com/full26/z$1 [NC,L]
e.g,
http://my-domain.com/full/a-one.txt
will mask the url
http://my-domain.com/full1/a-one.txt
Related
I have files:
search_result.php
new/search_result.php
mod_rewrite URL for these files are
www.domain.com/search?q=
www.domain.com/new/search?q=
The first one is working fine. But when I open www.domain.com/new/search?q=, its picking the file search_result.php in the root folder, I want it to pick the file new/search_result.php
The mod_rewrite code I'm using for both the folders is:
RewriteRule ^search$ search_result.php [QSA,L]
Thanks in advance!
Your rewrite rule should be like this:
RewriteRule ^([^/]+/)?search/?$ /$1search_result.php [QSA,L,NC]
I am working with a CMS, and up until today its been fine.
But i have discovered that the mod rewirte only works if the website is in the root directory. If I put the entire CMS into a folder, i get a 404.
Please help!
RewriteEngine on
Options +FollowSymLinks
RewriteRule ^([^/\.]+)/?$ /index.php?1=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /index.php?1=$1&2=$2 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /index.php?1=$1&2=$2&3=$3 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /index.php?1=$1&2=$2&3=$3&4=$4 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /index.php?1=$1&2=$2&3=$3&4=$4&5=$5 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /index.php?1=$1&2=$2&3=$3&4=$4&5=$5&6=$6 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /index.php?1=$1&2=$2&3=$3&4=$4&5=$5&6=$6&7=$7 [L]
Then you need to add the subfolder to your rewrite rule like this, for all of your rules.
RewriteRule ^([^/\.]+)/?$ /subfolder/index.php?1=$1 [L]
With your configuration apache will search for the index.php file in the root directory
Your script is extracting data that are between slashes like:
/test1/test2/ transfers into /index.php?1=test1&2=test2
but since you started using folder it works like:
/folder/test1/test2/ transfers into /index.php?1=folder&2=test1&3=test2
so the folder name is breaking your structure, you will need to fix every line with folder name or expression like this:
RewriteRule ^[^/\.]+/([^/\.]+)/?$ /folder/index.php?1=$1 [L]
So you will need to fix both regular expression and new path on every line, just replace folder with name of your folder and add [^/\.]+/ at start
If that doesnt work you may just need to fix regular expression only without adding /folder to the second part of line
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.
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]
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