htaccess redirect 301? - .htaccess

I have question how to redirect this link:
http://rude.su.lt/~veikutis/katalogas.php?link=dulkiu-siurbliai&id=1
To this link:
http://rude.su.lt/~veikutis/dulkiu-siurbliai/1/
With htaccess 301 redirect?

Add this to your .htaccess in DocumentRoot.
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.\w+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) /$1/ [R,L]
RewriteCond %{REQUEST_URI} ^/(\~veikutis)/([\w\d-]+)/([\d-]+)/$ [NC]
RewriteRule ^ /%1/katalogas.php?link=%2&id=%3 [L,QSA]
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{QUERY_STRING} flink=([\w\d-]+)&id=(\d+) [NC]
RewriteRule ^(~veikutis) /$1/%1/%2/? [L,R]

Related

redirect subdirectory to subdomain.subdomain.domain

i wanted to change the url for my subdirectory from "subdomain1.main.com/subdirectory" to "subdomain2.subdomain1.domain.com"
i tried the htaccess code below but it doesnt work. can someone please help?
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain1\.domain\.com$ [NC]
RewriteRule ^subdirectory/(.*)$ http://subdomain2.subdomain1.domain.com/$1 [L,NC,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain2.\subdomain1\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !(jpe?g|gif|bmp|png|tiff|css|js)$ [NC]
RewriteRule !subdirectory%{REQUEST_URI} [NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Try this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain1\.domain\.com$
RewriteRule ^subdirectory/(.*)$ http://subdomain2.subdomain1.domain.com/$1 [L,QSA,R=301]
RewriteCond %{HTTP_HOST} ^subdomain2\.subdomain1\.domain\.com$
RewriteCond %{REQUEST_URI} !^subdirectory/
RewriteRule ^(.*)$ /subdirectory/$1 [L,QSA]

301 redirect ssl in htaccess for codeigniter

This is my htaccess for codiegniter base website.
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^example\.com [OR]
RewriteCond %{HTTP_HOST} ^www.example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/
RewriteRule ^index\.php(/(.*))?$ example.com/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
Redirect 301 /blog/detail/4 https://example.com/blog/detail/4/blog-title
This is redirected url after use 301 :
https://example.com/blog/detail/4/blog-title/blog-title/blog-title/5/blog-title/blog-title/blog-title/blog-title/blog-title/blog-title/blog-title/blog-title/blog-title/blog-title/blog-title/blog-title/blog-title/blog-title/blog-title/blog-title/blog-title
I want this url:
https://example.com/blog/detail/4/blog-title

htacess redirect to subfolder result in too many http status 301 redirects

I have one question and I dont find the solution.
I habe a subfolder in my web root an I want to redirect all URLs to this subfolder without changing the URL.
Ex: domain.com/article123.html ->redirecting-> domain.com/subfolder/article123.html but in addressbar stays domain.com/artcle123.com
so I put the following in my root htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule !^subfolder/ /subfolder%{REQUEST_URI} [L,NC]
But now when I test an URL with http://httpstatus.io I get the following
301 → Error while fetching URL. 11 redirect
in subfolder i have another htaccess:
RewriteCond %{REQUEST_METHOD} =GET
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} "(.*)index.php"
RewriteRule ^index\.php$ %1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} ^(.*)\.(php|css|js|gif|jpg|jpeg|png)$ [NC]
RewriteRule ^(.+) - [L]
RewriteCond %{REQUEST_URI} (.*)?/admin/(.*)
RewriteRule ^(.+) - [L]
RewriteCond %{REQUEST_URI} (.*)?/images/(.*)
RewriteRule ^(.+) - [L]
RewriteCond %{REQUEST_URI} (.*)?/templates/(.*)
RewriteRule ^(.+) - [L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+) - [L]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^(.+) - [L]
##boosted CONTENT
RewriteRule (^[a-z]{2})/(.*/)?info/([A-Za-z0-9_-]+)\.html.* shop_content.php?language=$1&gm_boosted_content=$3&%{QUERY_STRING} [PT,L]
RewriteRule (.*/)?info/([A-Za-z0-9_-]+)\.html.* shop_content.php?gm_boosted_content=$2&%{QUERY_STRING} [PT,L]
##boosted PRODUCTS
RewriteRule (^[a-z]{2})/(.*/)?([A-Za-z0-9_-]+)\.html product_info.php?language=$1&gm_boosted_product=$3&%{QUERY_STRING} [PT,L]
RewriteRule (.*/)?([A-Za-z0-9_-]+)\.html product_info.php?gm_boosted_product=$2&%{QUERY_STRING} [PT,L]
##boosted CATEGORIES
RewriteRule (^[a-z]{2})/(.*/)?([A-Za-z0-9_-]+)/?.* index.php?language=$1&gm_boosted_category=$3&%{QUERY_STRING} [L]
RewriteRule (.*/)?([A-Za-z0-9_-]+)/?.* index.php?gm_boosted_category=$2&%{QUERY_STRING} [L]
I dont know why. Can anyone help?
root .htaccess looks fine, try this in subfolder/.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_METHOD} =GET
RewriteCond %{THE_REQUEST} /index\.php
RewriteCond %{REQUEST_URI} (.*)index\.php
RewriteRule ^index\.php$ %1 [R=301,L,NE]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} ^(.*)\.(php|css|js|gif|jpg|jpeg|png)$ [NC,OR]
RewriteCond %{REQUEST_URI} /(admin|images|templates)/
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
##boosted CONTENT
RewriteRule (^[a-z]{2})/(.*/)?info/([\w-]+)\.html shop_content.php?language=$1&gm_boosted_content=$3 [QSA,L,NC]
RewriteRule (.*/)?info/([\w-]+)\.html shop_content.php?gm_boosted_content=$2 [QSA,L,NC]
##boosted PRODUCTS
RewriteRule (^[a-z]{2})/(.*/)?([\w-]+)\.html product_info.php?language=$1&gm_boosted_product=$3 [QSA,L,NC]
RewriteRule (.*/)?([\w-]+)\.html product_info.php?gm_boosted_product=$2 [QSA,NC,L]
##boosted CATEGORIES
RewriteRule (^[a-z]{2})/(.*/)?([A-Za-z0-9_-]+)/? index.php?language=$1&gm_boosted_category=$3 [L,QSA,NC]
RewriteRule (.*/)?([\w-]+)/? index.php?gm_boosted_category=$2 [L,QSA,NC]

.htaccess RewriteRule url to new

Bonjour,
I try to redirect urls of a website
Example :
www.exemple.net/?p=2
to
www.exemple.net/index-2.html
www.exemple.net/?p=35
to
www.exemple.net/index-35.html
etc...
So i add this lines to my .htacess :
RewriteCond %{QUERY_STRING} ^(?)p=(.*)$ [NC]
RewriteRule .* /index-%1.html [L,R=301]
But i'm redirected to http://www.exemple.net/index-2.html?p=2
My .htaccess :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^exemple.net$
RewriteRule ^(.*) http://www.exemple.net/$1 [QSA,L,R=301]
RewriteCond %{QUERY_STRING} ^(?)p=(.*)$ [NC]
RewriteRule .* /index-%1.html [L,R=301]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Can you help me please ?
You need to add a question mark at the end of the destination to discard the query string:
RewriteRule .* /index-%1.html? [L,R=301]
Alternatively, use the QSD flag:
RewriteRule .* /index-%1.html [QSD,L,R=301]
Try :
#Redirecting /?p=2
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/\?p=([^&\s]+) [NC]
RewriteRule ^ /index-%1.html? [NE,NC,R,L]
#Redirecting /transfer?p=2
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/transfer\?p=([^&\s]+) [NC]
RewriteRule ^ /transfer-%1.html? [NE,NC,R,L]
#Redirecting /blog?p=2
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/blog\?p=([^&\s]+) [NC]
RewriteRule ^ /blog-%1.html? [NE,NC,R,L]

Exclude htaccess for admin area

I have htaccess like below, it includes admin also but I don't want htaccess to effect my admin area, so what changes should I do in below code?
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !\.\w+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) /$1/ [R,L]
RewriteCond %{REQUEST_URI} ^/(my_site)/([\w\d-]+)/$ [NC]
RewriteRule ^ /%1/?file_name=%2 [L,QSA]
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{QUERY_STRING} file_name=([\w\d-]+) [NC]
RewriteRule ^(my_site) /$1/%1/? [L,R]
Previous conversation: Redirection through htaccess not working
Thanks in advance.
Add the first line.
RewriteCond %{REQUEST_URI} !/admin
RewriteCond %{REQUEST_URI} ^/(my_site)/([\w\d-]+)/$ [NC]
RewriteRule ^ %1/?file_name=%2 [L,QSA]

Resources