.htaccess redirect not properly - .htaccess

I would like to redirect my pages in the following ways:
www.example.com/index.cfm?locale=it -> www.example.com/it
and I would like to access the same page when I type:
www.example.com/it
I wrote an htaccess file but it causes a redirect loop. Here is the file:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#REWRITE RULES
#---------------------
RewriteCond %{QUERY_STRING} ^locale=(it|en|fr|de|es)$
RewriteRule ^index\.cfm$ %1? [R=302,L]
RewriteCond %{REQUEST_URI} !^index\.cfm
RewriteRule ^(it|en|fr|de|es)/?$ index.cfm?locale=$1 [L]
</IfModule>
Could you help me to resolve it?
Thanks!!!

You can try it this way.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
Rewrite ^ - [L]
RewriteCond %{THE_REQUEST} ^GET\ /index\.cfm\?locale=(it|en|fr|de|es)
RewriteRule ^ %1? [R=302,L]
RewriteRule ^(it|en|fr|de|es)/?$ index.cfm?locale=$1 [L]

Try this:
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com/it[nc]
RewriteRule ^(.*)$ http://www.example.com/it/$1 [r=301,nc]
//301 Redirect Old File
Redirect 301 www.example.com/index.php?locale=it www.example.com/it
//301 Redirect Entire Directory
RedirectMatch 301 www.example.com/index.php?locale=it(.*) www.example.com/it/$1

Related

url rewriting with QUERY_STRING

I would like to rewrite http://example.com/test/index.php?id=123
to http://example.com/test/item/123/ and http://example.com/test/index.php?id=123 redirect to the human friendly url.
I don't know what is wrong in my htaccess :
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /test/
RewriteCond %{QUERY_STRING} ^id=([a-z0-9]+)$ [NC]
RewriteRule ^/item/%1/? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^item/([a-z0-9]+)/$ index.php?id=$1 [L]
You can use the following RewriteRule in your /test/.htaccess file
Options +FollowSymLinks -MultiViews
RewriteEngine on
#redirect old url to the new one
RewriteCond %{THE_REQUEST} /test/index\.php\?id=([^\s]+) [NC]
RewriteRule ^ /test/item/%1? [L,R=301]
#internally map new url to the old one
RewriteRule ^item/(.+)/?$ /test/index.php?id=$1 [L,NC]

Why my single page htaccess redirect does't work?

Could You help me to fix my htaccess file for page homestack.pl? I have a problem with redirect page homestack.pl/categories to homestack.pl/kategorie. Thanks in advance.
Bug line added by me: RedirectMatch 301 /categories /kategorie
I results I have too many redirections, and page does't open.
Options -Indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
RedirectMatch 301 /categories /kategorie
</IfModule>

htaccess redirect for url with query string

I want to redirct this url http://www.example.com/tev/?user-register=registered
to the home page http://www.example.com/
I have the following code in my htaccess file but it isn't working
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^user-register=registered$
RewriteRule .* http://www.example.com/ [R=301,L]
Try with:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^user-register=registered$
RewriteRule ^tev/?$ http://www.example.com/? [NC,R=301,L]

how to redirect my www.example.com/index.html file www.example.com/index

how to redirect my www.example.com/index.html file www.example.com/index using .htacces
and if my url is like www.example.com/test1/index.htm
or
ww.example.com/test/test2/index.htm
how to redirect the pages with out extensions
# Redirect everyone but for me
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^127\.0\.0\.1
RewriteRule .* http://www.example.com [R=302,L]
above code i found in web but it's not working ... how to specified .htacces rules
You can use these rules in root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+(.*?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.html -f [NC]
RewriteRule ^(.+?)/?$ /$1.html [L]

301 redirect with htaccess & textpattern

Trying to set up a 301 redirect for a change in domain. I'm using Textpattern which already has a mod rewrite. When adding the redirect I'm prompted with a error page on the site, stating that the page has resulted in too many redirects!
This is the htaccess file in use...
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /relative/web/path/
RewriteRule (.*) http://www.domain.com/$1 [R=301,L] #(this has been added to the default textpattern htaccess file)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*) index.php
RewriteCond %{HTTP:Authorization} !^$
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>
Many thanks for any advise you can give.
From what domain you try to redirect? May be you have set cycling - trying to redirect from site.com to site.com?
Add this after RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?!www.yournewdomain.com$).*$
RewriteRule (.*) http://www.yournewdomain.com/$1 [R=301,L]

Resources