htaccess redirect to lang page - .htaccess

How can I redirect
from
http://host_name.com/booking?param=1&param=2
to
http://host_name.com/fr/booking?param=1&param=2
I tried it this way, but it doesn't work
RewriteCond %{HTTP_HOST} ^(.*)\/booking(.*)
RewriteRule ^/booking(.*) /fr/booking$2 [L, R=301]

So you should be able to do this to redirect the query string to a new one.
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /+booking\?param=([^&\s]+)&param=([^&\s]+)
RewriteRule ^ /fr/booking?param=%1&param=%2 [L, R=302]
Let me know how this works for you.

Related

Htaccess www to non-www but keep the url intact

I think that this is rather simple, but I just can't wrap my head around it.
I have a domain like https://www.example.com
I want to rewrite it to https://example.com
That works. But I am also rewriting other urls like https://www.example.com/privacy
If I try to rewrite these too the user is always redirected to https://example.com/privacy.php
How do I prevent my server to show the actual filename instead of its rewritten url?
My code looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^checkout checkout.php [L]
RewriteRule ^imprint imprint.php [L]
RewriteRule ^privacy privacy.php [L]
RewriteRule ^terms terms.php [L]
RewriteRule ^allergy allergy.php [L]
RewriteRule ^nutrition nutrition.php [L]
RewriteRule ^order/([A-Z]*)?$ confirmation.php?lang=&id=$1 [L,QSA]
Any help is appreciated.
Regards
Have it this way:
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^(checkout|imprint|privacy|terms|allergy|nutrition)/?$ $1.php [L]
RewriteRule ^order/([a-z]+)/?$ confirmation.php?lang=&id=$1 [L,QSA,NC]
Make sure to test after clearing your browser cache. Problem appears to be due to your patterns not using end anchor.
I have combined your multiple similar rules into one rule.

.htaccess SEO friendly URL with queryString

I have a page like:
page.php?mode=dashboard&hl=en
and i want to use like:
site.com/dashboard?hl=en
how must i use RewriteRule? Thanks...
EDIT: I think this is not possible with .htaccess. Need to use javascript.
wish it helps you
# Redirect /Category.php?Category_Id=10&Category_Title=some-text
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^Category_Id=(\d+)&Category_Title=([\w-]+)$
RewriteRule ^Category\.php$ /Category/%1/%2? [R=301,L]
You may be able to use this code in site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /page\.php\?mode=([^\s&]+)&(hl=[^\s&]+) [NC]
RewriteRule ^ /%1?%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\w-]+)/?$ page.php?mode=$1 [L,QSA]

htaccess using RewriteRule and RewriteCond to redirect specific url

I have to redirect (301) from
http://domain/index.php to
http://domain/
I've done it with following rules:
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
Ok. it works, BUT I do NOT want to allow redirect from urls like:
http://domain/asd/index.php
I've tried to change condition like:
RewriteCond %{THE_REQUEST} ^/index.php
RewriteCond %{THE_REQUEST} ^/index.php
but no success.
So, how to redirect ONLY from http://domain/index.php to http://domain/
ps: I do not want to use REDIRECT command
Try this:
RewriteRule ^index.php$ / [R=301,L]
You can use the following rule :
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/index\.php\s [NC]
RewriteRule ^ / [L,R]

Redirect URLs containing specific string to https

I want to redirect my member registration URLs to HTTPS using htaccess. So:
http://example.com/product/register/*
...And any pages under that such as:
http://example.com/product/register/details
http://example.com/product/register/payment
I tried the following, but I'm not sure I'm even on the right track:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond $1 ^(register/*) [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Any help appreciated.
Have it this way:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} /product/register/ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

.htaccess - 301 redirect with no query string, leave as is if query string

I put in a 301 redirect for my /index.php as recommended for SEO purposes. Unfortunately this prevents any params being accepted.
example.com/index.php should redirect to example.com
example.com/index.php?anything should stay at example.com/index.php?anything
example.com/index.php?f=bar&b=foo should stay at example.com/index.php?f=bar&b=foo
My attempted fix is below:
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s\/index\.php\s
RewriteCond %{QUERY_STRING} =""
RewriteRule . http://${HTTP_HOST}/ [R=301,L]
Turns out the answer for the scenario is a combination of Deadooshka's answer and a POST fix.
RewriteCond %{THE_REQUEST} \s\/index\.php\s
RewriteCond %{QUERY_STRING} =""
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^(.*)index.php$ /$1 [R=301,L]

Resources