Redirect Chain URL - .htaccess

how can I solve the following redirect chain problem ?
http://www.website.com/ > https://www.website.com/ > https://website.com/
I want the forwarding above to be like
http://www.website.com/ > https://website.com/
Please help.

Try:
RewriteCond %{HTTP_HOST} !^website\.com$
RewriteRule ^ https://website\.com [R=301,L]
Place this on top of .htaccess.

Related

RewriteRule with 1 aliased path

I want to redirect several pages to a same page :
/products/categories-35512 > /catalog/products
/products/categories-152 > /catalog/products
/products/categories-5632 > /catalog/products
...
For this, I need to use an alias. I tried to use this code in my .htaccess without success:
RewriteEngine On
RewriteRule ^/products/categories\/(.*)$ /catalog/products [L,R=301,NE]
How do I proceed to resolve my problem?
Thanks for your help.
Try this
RewriteEngine On
RewriteRule ^categories http://www.example.com/catalog/products/ [R=301,L]
This will redirect all the URLs that start with categories to
/catalog/products/

Redirect image URLs to new directories

I am migrating my site to a new software and need to redirect the old image URLs to new directory structures. This is the sort of pattern I need to redirect:
http://domain.com/galleries/directory1/*.gif > https://i.domain.com/galleries/1/big/*.gif
http://domain.com/galleries/directory2/*.gif > https://i.domain.com/galleries/2/big/*.gif
http://domain.com/galleries/directory3/*.gif > https://i.domain.com/galleries/3/big/*.gif
http://domain.com/galleries/directory4/*.gif > https://i.domain.com/galleries/4/big/*.gif
and so on
And also:
http://domain.com/upload/*year*/*month*/*day*/*.gif > https://i.domain.com/galleries/*year*/big/*.gif
Any help for what htaccess rules to use would be much appreciated. Thank you
The below should do the trick. However, be careful of collisions in file names from your uploads as the question doesn't specify different months and days in the target url.
RewriteEngine on
RewriteRule ^upload/([0-9]*)/[0-9]*/[0-9]*/(.*.gif)$ "https://i.domain.com/galleries/$1/big/$2"
RedirectMatch "^/galleries/directory(.)/(.*\.gif)$" "https://i.domain.com/galleries/$1/big/$2"
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(domain\.com)$ [NC]
RewriteRule ^(galleries)/directory(\d+)/(.+?\.gif)$ http://i.%1/$1/$2/big/$3 [L,NC,R=301]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(domain\.com)$ [NC]
RewriteRule ^upload/(\d+)/\d+/\d+/(.+?\.gif)$ http://i.%1/galleries/$1/big/$2 [L,NC,R=301]

htaccess rewrite rule for subdomain results to redirect loop

Below is my htaccess config
RewriteEngine On
# if the domain starts with "apply."
# i.e. apply.domain.com
# redirect to application URI
RewriteCond %{HTTP_HOST} ^apply\. [NC]
RewriteRule !^formwizard /formwizard/apply [R=301,L,NC]
I have tried it, and when I go to http://apply.domain.com/ it successfully redirects to http://apply.domain.com/formwizard/apply.
My problem is, once it redirects to that URI, it goes to a redirect loop.
Can anyone please help hit me what is wrong with my config?
Background:
I have 3 subdomains: www.domain.com, apply.domain.com, and admin.domain.com. It all references to the same source codes and just managed by my htaccess.
Once the person goes to apply.domain.com, it should be redirected to the application page which is /formwizard/apply.
PS. I don't want to depend too much on the backend codes because I believe this is a server config problem.
Thanks in advance!
If there are more rules then this rule might be getting impacted by them. Modify this rule to this:
RewriteCond %{HTTP_HOST} ^apply\. [NC]
RewriteCond %{THE_REQUEST} !/formwizard/ [NC]
RewriteRule ^ /formwizard/apply [R=301,L,NC]
Also make sure this is very first rule below RewriteEngine On line.

htaccess redirect index.php?/* to ?/*

Basically I need to do exactly what the title says.
I have a client site using the following url structures:
http://www.example.co.uk/index.php?/<folder>/<file>
http://www.example.co.uk/?/<folder>/<file>
I need to redirect index.php?/ to ?/
Cheers for your help!
This should work for you:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /index\.php\?/(.*)\ HTTP
RewriteRule ^ /?/%2 [R=301,L]
It should change index.php?/folder/file to ?/folder/file

.htaccess php to html

sorry for this simple question, however i still cant get my head round using .htaccess
I'm trying to convert:
search.php?s=dvd&page=1
to
/Search/dvd/page1.html
Thanks,
Jack
I think something like:
RewriteRule ^search/([A-Za-z]+)/page([0-9]+)\.html$ search.php?$1&page$2
Should do the trick.
Further reading here: http://www.webforgers.net/mod-rewrite/mod-rewrite-syntax.php
you must put your link "/Search/dvd/page1.html" in the page and with htaccess it will convert to the "search.php?s=dvd&page=1" . i hope it be usefull :)
sample correct htaccess code :
RewriteEngine On
RewriteRule Search/(\d+)/page?(\d+)\.html$ search.php?s=$1&page=$2 [NC,L]
If I understand the question OP wants to convert php to html redirection. Try this rule in your .htaccess file:
RewriteEngine on
Options +FollowSymlinks -MultiViews
# to match /search.php?s=dvd&page=1
RewriteCond %{QUERY_STRING} ^s=([^&]*)&page=(.*)$ [NC]
RewriteRule ^search\.php/?$ /Search/%1/page%2.html? [R,L,NC]
# to match /search.php?page=12&s=dvd
RewriteCond %{QUERY_STRING} ^page=([^&]*)&s=(.*)$ [NC]
RewriteRule ^search\.php/?$ /Search/%2/page%1.html? [R,L,NC]
R=301 will redirect with https status 301
L will make last rule
NC is for no case comparison
%1 and %2 are the query parameter values
I think you want make clean URI, so if user type url like this:
search/televisi/page4.html
it same as like search.php?s=dvd&page=1
Add this code:
RewriteEngine On
RewriteRule ^search/([a-z]+)/page([1-9]+).html$ search.php?s=$1&page=$2

Resources