I'm trying to set redirects based on time but I'm having a difficult time. It is a WP site. Essentially, I will redirect the "page1" to different pages based on time of day on day only. as an example: from 2 to 3pm - redirect to page2, from 3 to 4pm - redirect to page3, etc. For the moment, I'm just trying to get even one to work to test out the process and it's not working. This is the code I'm using for testing:
# BEGIN WordPress
# The directives (lines) between `BEGIN WordPress` and `END WordPress` are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# Following Added by Pardeep
# CONDITIONAL REDIRECTS
# TEST TIME ZONE
#RewriteEngine On
RewriteCond %{REQUEST_URI} /page1
#RewriteCond %{TIME} >=20210304150000
#RewriteCond %{TIME} <20210304160000
RewriteRule ^ https://www.example.com/page2 [R=301,L]
Related
I am wondering how can I redirect the old homepage
https://blog.example.com/ to the new one https://www.example.com/ratgeber/
I have tried to redirect it via a WordPress Plugin, but when I insert the origin URL and the target URL I am getting the error message "ERR_TOO_MANY_REDIRECTS" .. for a better understanding of the issue you can take a look at the extract from a status-code-checker. I do not know how to solve this loop. Both hostnames point to the same place.
Could please someone tell me the correct syntax to put in the .htaccess? Hereby you can see all the directives included at the present moment in this file. The very first two lines of code are unfortunately not working as desired.
RewriteCond %{HTTP_HOST} ^blog\.(terminsvertreter\.com) [NC]
RewriteRule ^https://www.%1/ratgeber%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
# Die Anweisungen (Zeilen) zwischen `BEGIN WordPress` und `END WordPress` sind
# dynamisch generiert und sollten nur über WordPress-Filter geändert werden.
# Alle Änderungen an den Anweisungen zwischen diesen Markierungen werden überschrieben.
<IfModule mod_rewrite.c>
RewriteBase /
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule . https://www.terminsvertreter.com/ratgeber%{REQUEST_URI} [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I want to rewrite this specific URL:
https://www.domain.test/cart/?query_action=abc
...to this URL:
https://www.domain.test/cart/
The "abc" part is variable, everything else is exactly what I want to rewrite. I added these lines to my .htaccess file:
RewriteCond %{QUERY_STRING} ^query_action\=
RewriteRule ^folder/$ /folder/? [L]
When I run this on my local environment, it works. But when I upload to our development server (WP Engine), it does not work. Are there incompatibilities with .htaccess between different servers? Does my code's proximity with WordPress' default code have anything to do with it? Is there something I can tweak in my rewrite to improve it?
Here is my entire .htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^query_action\=
RewriteRule ^folder/$ /folder/? [L]
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<Files xmlrpc.php>
order deny,allow
deny from all
</Files>
The logic of RewriteCond somehow continues to elude me, so maybe somebody could take a look at my current problem:
I have to sort a very (very) confusing page that has a quite poorly configured virtual domain system in place. The easiest way for the moment seems to be redirects in the .htaccess.
Basically, I want to express the following to mod_rewrite:
IF request string contains the directories /aaa or /bbb
AND the subdomain is not www. , THEN redirect the request to http://www.foo.com/ and keep any URI-parts that might follow, like/aaa/target-dir/index.html .
Same for /ddd: if subdomain is not sub1., redirect towards http://sub1.foo.com/ddd (as well as for 2 more subdomains).
My attempt so far was
RewriteCond %{HTTP_HOST} !^www\.foo\.com [NC]
RewriteCond %{REQUEST_URI} /aaa/|/bbb/
RewriteRule ^(.*)$ http://www\.foo\.com/%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} !^sub1\.foo\.com [NC]
RewriteCond %{REQUEST_URI} /ddd/|/eee/
RewriteRule ^(.*)$ http://sub1\.foo\.com/%{REQUEST_URI} [R=301,L]
but that did not work for some reason.
What's my mistake? Anyone got an idea?
edit: The complete .htaccess as follows
##
# #package Joomla
# #copyright Copyright (C) 2005 - 2012 Open Source Matters. All rights reserved.
# #license GNU General Public License version 2 or later; see LICENSE.txt
##
##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations. It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file. If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's. If they work,
# it has been set by your server administrator and you do not need it set here.
##
## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks
## Mod_rewrite in use.
RewriteEngine On
## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.
## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects
##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##
# RewriteBase /
## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
## OSMap Adjustment
RewriteCond %{REQUEST_URI} ^/sitemap.xml
RewriteRule .* /index.php?option=com_osmap&view=xml&tmpl=component&id=3
RewriteCond %{REQUEST_URI} ^/sub1-sitemap.xml
RewriteRule .* /index.php?option=com_osmap&view=xml&tmpl=component&id=1
RewriteCond %{REQUEST_URI} ^/sub2-sitemap.xml
RewriteRule .* /index.php?option=com_osmap&view=xml&tmpl=component&id=2
## Redirect non-www to www
RewriteCond %{HTTP_HOST} !^(www|sub1|sub2|sub3).foo.com$
RewriteRule ^(.*)$ http://www.foo.com/$1 [R=301,L]
## RewriteEngine On
## RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
## RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
## /aaa , /bbb => www.foo.com
RewriteCond %{HTTP_HOST} !^www\.foo\.com [NC]
RewriteCond %{REQUEST_URI} /aaa/|/bbb/
RewriteRule ^(.*)$ http://www\.foo\.com/%{REQUEST_URI} [R=301,L]
## /ddd, /eee => sub1.foo.com
RewriteCond %{HTTP_HOST} !^sub1\.foo\.com [NC]
RewriteCond %{REQUEST_URI} /ddd/|/eee/
RewriteRule ^(.*)$ http://sub1\.foo\.com/%{REQUEST_URI} [R=301,L]
## /fff, /ggg => sub2.foo.com
RewriteCond %{HTTP_HOST} !^sub2\.foo\.com [NC]
RewriteCond %{REQUEST_URI} /fff/|/ggg/
RewriteRule ^(.*)$ http://sub2\.foo\.com/%{REQUEST_URI} [R=301,L]
I want to add one get parameter to the every url on my wprdpress website except the index page.
For example,
Consider website name to be www.example.com
If www.example.com is hit than nothing should happen
But if I hit www.example.com/events than a get parameter viz. "home" be appended to it. Final URL should be as follows:
www.example.com/events/?home
I want to use this parameter for further processing.
my current .htaccess file contains following
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{QUERY_STRING} !lp-variation-id
RewriteRule ^go/([^/]*)? /wp-content/plugins/landing-pages/modules/module.redirect-ab-testing.php?permalink_name=$1 [QSA,L]
RewriteRule ^landing-page=([^/]*)? /wp-content/plugins/landing-pages/modules/module.redirect-ab-testing.php?permalink_name=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
and i m working on wordpress project.
Try this:
RewriteCond !^/$
RewriteRule ^/(.*)$ /$1?home
Depending on your hosting environment the URL may or may not start with a slash, so you might have to remove it from the RewriteRule.
I have a Joomla installation with search-friendly-urls at the root level of the domain, but my host is giving me access to my website stats (which requires authentication) in domain.com/stats, and I cannot see it, just a Joomla generated 404 error.
I thought this might be due to the .htaccess so I tried adding this line to the top:
RewriteRule ^(/stats) - [L]
but I still get the 404. This is what the rest of the .htaccess: looks like
## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks
#
# mod_rewrite in use
RewriteEngine On
########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteCond %{REQUEST_URI} !^/stats
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root)
# RewriteBase /
########## Begin - Joomla! core SEF Section
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section
EDIT: does any of these (directly after RewriteEngine On) help?:
RewriteCond %{REQUEST_URI} ^/stats/.* [NC]
RewriteRule .* - [L]
or
RewriteCond %{ENV:REDIRECT_STATUS} 200 RewriteRule .* - [L]
also, try enabling the
RewriteBase /
if it still doesn't work, and if you are able to change to server / virtual host config, try logging the rewrite process.
EDIT END
try adding a
RewriteCond %{REQUEST_URI} !^/stats
before the
RewriteRule ^(.*)$ index.php [F,L]