Redirect old homepage to the new one within the same site - .htaccess

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

Related

.htaccess redirect URL with specific query string parameter, compatibility with multiple servers

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>

Conditional Time based htaccess redirects

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]

Add get variables to url throung htaccess file

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.

CodeIgniter controllers are not loading and giving a 404 error

I am testing gocart (http://gocartdv.com/) and I have installed it in a subfolder called vine-cart, http://www.icas-v.org/vine-cart.
The default controller loads fine but the rest of the controllers return an error 404 message. I have looked through all the similar problems and the possible solutions, implemented them and they don't seem to work.
Please have a look at my configuration settings:
/---------------------------------|.htaccess file settings|---------------------------------/
RewriteEngine On
RewriteBase /vine-cart
### Canonicalize codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(cart(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
###
# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
</IfModule>
/---------------------------------|Config.php settings|---------------------------------/
$config['base_url'] = 'http://www.icas-v.org/vine-cart/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
/---------------------------------|routes file settings|---------------------------------/
$route['default_controller'] = "cart";
//this for the admininstration console
$route['admin'] = 'admin/dashboard';
$route['admin/media/(:any)'] = 'admin/media/$1';
Ive been trying to debug this for days. Please help.
Can you try this htaccess code? remove rewritebase.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /vine-cart/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /vine-cart/ [L]
</IfModule>
What did you name your controller file?
Also it's a good practice to comment out lines on your .htaccess as you test them 1 by 1 if its causing issues.

ExpressionEngine on MediaTemple - removing index.php results in "no input file specified"

I have an MT site with the standard ExpressionEngine htaccess code to remove index.php and the home page works, and all other pages work if I put index.php in the URL. Without it, I get "no output file specified". It works on my local and non-MT server, so I know its an environment thing. What in the htaccess needs to be changed to make it work on MT?
<IfModule mod_rewrite.c>
# Enable Rewrite Engine
# ------------------------------
RewriteEngine On
RewriteBase /
# Use Dynamic robots.txt file
# ------------------------------
RewriteRule robots\.txt /robots.php [L]
# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/admin/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
# Standard ExpressionEngine Rewrite
# ------------------------------
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
Thanks to #danielcgold for the answer via twitter:
Try using this line RewriteRule ^(.*)$ /index.php?/$1 [L] and note the ? after index.php
I posted a Gist last night with my standard rewrite rules for all my ExpressionEngine sites on (mt).
## BEGIN Expression Engine Rewrite
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteRule ^(.*)$ /index.php?/$1 [L]
## END Expression Engine Rewrite
Using EE 2.7.0 and Mediatemple's Grid service (formerly "GS"), I've had luck using the standard .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
but then going into the AccountCenter > [mydomain.com] > PHP Settings, and changing the PHP version from 5.5.1 CGI (latest) to 5.3.7 CGI (stable).
I posted this solution on the ExpressionEngine Stack Exchange site, but in a nutshell the shared hosting environment we had to use was forced to use FastCGI, and we couldn't modify any CGI or PHP configurations.
In an attempt to create the $_SERVER['PATH_INFO'] variable myself, what worked for me was this 3 step 'custom' approach:
First, in ExpressionEngine > CP Home > Admin > System Administration > Output And Debugging, I set Force URL query strings to No.
Next, as mentioned in previous answers, I changed the .htaccess directive from RewriteRule ^(.*)$ /index.php/$1 [L,QSA] to RewriteRule ^(.*)$ /index.php?/$1 [L,QSA] (extra ? after index.php).
Finally, I added this piece of custom PHP code to the top of site root's index.php file to "force" the $_SERVER['PATH_INFO'] variable into accurate existence:
<?php
$path = $_SERVER['REQUEST_URI'];
$pos = strpos($path, '?');
if ($pos !== false)
$path = substr($path, 0, $pos);
$_SERVER['PATH_INFO'] = $path;
/**
* ExpressionEngine - by EllisLab
...
...
I hope this helps someone! I really pulled my hair out trying to find somewhat more elegant solutions!

Categories

Resources