Redirect on specific date/time with htaccess - .htaccess

Is it possible to redirect on specific date/time?
For Example ... what would be htaccess code for redirecting website on 30th July, 10 AM?
Update
Here is my current htaccess code, where my requirement (see above) will be included
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R,L]
RewriteCond $1 !^(index\.php)
RewriteCond %{REQUEST_URI} !(\.png|\.jpg)$
RewriteRule ^(.*)$ index.php?l=$1 [L]
RewriteCond %{THE_REQUEST} ^GET\ /(.+)\.html [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [NC,L]

You can use this rule (you need to enable mod_rewrite)
RewriteEngine On
RewriteCond %{TIME} >=20180730100000
RewriteCond %{TIME} <20180730110000
RewriteRule ^ /other_page [R,L]
It will (temporarily) redirect to /other_page between 10:00:00 AM and 10:59:59 AM (only on July 30)
Explanation: %{TIME} value format is yyyymmddhhiiss where:
yyyy = year (4 digits)
mm = month (2 digits)
dd = day (2 digits)
hh = hour (2 digits)
ii = minutes (2 digits)
ss = seconds (2 digits)

Yes it's possible :
RewriteCond %{TIME_YEAR}%{TIME_MON}%{TIME_DAY}%{TIME_HOUR} <201808010000
RewriteCond %{TIME_YEAR}%{TIME_MON}%{TIME_DAY}%{TIME_HOUR} >201807301000
RewriteRule ^$ /destination/url.html [R=301,L]

Related

handle in a different way 2 similar urls in htaccess apache

Hi guys i need help with apache htaccess.
I've this 2 url:
test / en / guns2 / beretta/
test / en / 1564 / vibram-beretta-m9a3/
how i can catch in a different way this 2 situations?
actually i've this htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/test/admin[NC]
RewriteCond %{REQUEST_URI} !^/test/(it|en) [NC]
RewriteRule ^(.*)$ /test/en/$1 [R=301,L,QSA]
RewriteRule ^([\w-]+)/([\w-]+)/(\d+)/([\w-]*)$ /test/index.php?detMod=$3 [L,QSA,NC]
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]*)$ /test/index.php?page=$2&category=$3 [L,QSA,NC]
But i need another rule for the case of number (1564) instead of the (guns2)
Use \d+ to match only numbers and use [\w-]+ to match alphanumerics, _ and -:
^([\w-]+)/([\w-]+)/(\d+)/([\w-]*)$
and
^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]*)$
Suggested .htaccess:
RewriteCond %{REQUEST_URI} !^/test/admin[NC]
RewriteCond %{REQUEST_URI} !^/test/(it|en) [NC]
RewriteRule ^(.*)$ /test/en/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([\w-]+)/([\w-]+)/(\d+)/([\w-]*)$ test/index.php?detMod=$3 [L,QSA,NC]
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]*)$ test/index.php?page=$2&category=$3 [L,QSA,NC]

remove comma (%2C), apostrophe (%27), colon (%3A) from url

How to remove comma (%2C), apostrophe (%27), colon (%3A) from title of the url using htaccess
my url is
https://xklsv.me/Funding-Friday%3A-Jelly2/fred/August-7th-2020
desired url
https://xklsv.me/Funding-Friday:-Jelly2/fred/August-7th-2020
https://xklsv.me/Tactics%2C-Political-Tactics/BigRedCar/August-9th-2020
desired url
https://xklsv.me/Tactics,-Political-Tactics/BigRedCar/August-9th-2020
this is my code what i have tried
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^title=([^/]+)/([^/]+)/([^/]+)/(.+)$
RewriteRule ^viewblog1\.php$ /%1/%2/%4? [R=301]
RewriteRule ^viewblog1/([\w+%]{2,50})$ /viewblog1.php?q=$1 [QSA,L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ viewblog1.php?title=$1&user=$2&date=$3
RewriteRule ^([^/]+)/([^/]+)/(.+)$ viewblog1.php?title=$1/$2/$1/$3 [L]
RewriteRule ^(.*):(.*)$ /viewblog1.php?title=$1/$2/$1/$3 [L]
RewriteRule ^(.*),(.*)$ /viewblog1.php?title=$1/$2/$1/$3 [L]
You may use these 3 redirect rules at top of your .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+(\S*?)%3A(\S*)
RewriteRule . /%1:%2 [L,NE,R=301]
RewriteCond %{THE_REQUEST} \s/+(\S*?)%2C(\S*)
RewriteRule . /%1,%2 [L,NE,R=301]
RewriteCond %{THE_REQUEST} \s/+(\S*?)%27(\S*)
RewriteRule . /%1'%2 [L,NE,R=301]

How to redirect in htaccess based on query parameters

I would like to strip query parameters then redirect to main page when the word "utm" will occur in the URL, do you have any ideas how to do it?
for example:
http://example.com/?utm=cxzcxz
on http://example.com/
BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} "utm" [NC]
RewriteRule (.*) /$1? [R=301,L,QSD]
RewriteCond %{QUERY_STRING} !=""
RewriteCond %{QUERY_STRING} !^p=.*
RewriteCond %{QUERY_STRING} !^s=.*
RewriteCond %{REQUEST_URI} !^/wp-admin.*
RewriteRule ^(.*)$ /$1? [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

.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