Redirect URL from https://www.oldweb.example/Vidz to https://www.newweb.example/Vidz - apache

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]
Redirect 301 /Vidz https://www.oldweb.example/Vidz
Redirect 301 /Vidz https://www.oldweb.example/Helium
Above is my code on. htaccess, and it is not working according to what it needed to be.
Right now, my site's pages namely https://www.oldweb.example/Vidz and the other one redirects on to https://www.newweb.example. What I would like to happen is for them to redirect to their respective new links which will be mentioned below.
https://www.oldweb.example/Vidz must be redirected to https://www.newweb.example/Vidz As well as https://www.oldweb.example/Helium must be redirected to https://www.newweb.example/Helium

Related

Redirecting the url entered with htaccess to a different location in the same way

When I enter my example.com url I want to redirect to example.com/en/ but when I enter example.com/demo I want to redirect to example.com/us/demo. The word demo here is just variable. how can I do that ?
My .htaccess code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /tr/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /tr/index.php [L]
</IfModule>
Try the following before your existing directives (ie. before the <IfModule> section):
# Redirect "/" to "/en/"
RewriteRule ^$ /en/ [R,L]
# Redirect "/demo" to "/us/demo"
RewriteCond %{REQUEST_URI} !^/(en|us)/
RewriteRule (.*) /us/$1 [R,L]
The first rule redirects example.com/ to example.comn/en/. The second rule redirects everything else to /us/<url>, providing the URL-path does not already start /en/ or /us/.
If you also need to make an exception for your static assets... eg. Should a request for /assets/images/img.png also be redirected? Then include an additional condition (as the 2nd condition) on the second rule:
# Redirect "/demo" to "/us/demo" (and exclude static assets)
RewriteCond %{REQUEST_URI} !^/(en|us)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /us/$1 [R,L]
Note that these are 302 (temporary) redirects.

Apache - .htaccess - Redirect only URLs ending with "/feed"

I would like to redirect only URLs ending on /feed (constant 404s - from Amazon servers? - using a wrong url). How can I configure the redirect?
Currently my .htaccess file looks like this. I am trying to add a folder /category before the incoming url.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Redirect 301 /mobile-home /
Redirect 301 /destinations-3/greeter-destinations/ /greeter-destinations/
Redirect 301 /destinations-3/ /category/destinations/
RewriteRule ^index\.php$ - [L]
#RewriteCond %{REQUEST_URI} !^/content/
#RewriteRule ^(.*)/feed$ content/category/$1/feed [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The 2 "#" lines were taken from another thread but they do not have any effect.
Thanks for your help
The code below will perform a permanent redirect for URLs matching your pattern:
RewriteRule ^destinations/(.*)/feed$ /category/destination/$1/feed [L,R=301]
I hope this helps!

Creating .htaccess for Vue.js website with prerendering

I have .htaccess file with content below (it's slightly modified example from vue-router documentation):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
</IfModule>
I want to:
redirect from www. to non-www (this is in in the above code and works)
add a rule to remove trailing slashes (so, a server should redirect from http://example.com/ to http://example.com)
redirect URLs like http://example.com/? to http://example.com
I tried to remove trailing slashes by:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
But server falls into redirect loop (301 to 302, 302 to 301, and so on) and I don't have any idea how to fix this.
The website is based on Vue.js with prerendering, so if it has http://example.com/contact page, the server should render file from /contact/index.html directory.

how to forward url containing certain directory to same url on new subdomain

Just launched a new site. Kept the old site, but assigned it to a subdomain.
I need to forward requests for old site URLs to the new subdomain.
Old site URLs all have this structure: "www.oldsite.com/BMT/xxxxxx" where the "/BMT/" directly follows the .com.
I need my .htaccess to forward URLs like that to "subdomain.oldsite.com" instead of "www.oldsite.com", keeping the same path after the "/BMT/"
Any URLs without the "/BMT/" should not be redirected.
From my research, I think this might work
RewriteCond %{REQUEST_URI} ^/BMT http://subdomain.oldsite.com%{REQUEST_URI} [L,R=301]
Am I on the right track?
If so, where should I add it in my current .htaccess?
Current .htaccess is:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Yes, you are right,
RewriteCond %{REQUEST_URI} ^/BMT [NC]
is a condition ,if it matchs the request uri string starting with /BMT then the rule will redirect the uri to http://sub.domain .
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} ^/BMT [NC]
RewriteRule ^(.*)$ http://sub.oldsite.com/$1 [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

.htaccess 301 redirect not working correctly. Need to force HTTPS

We would like to force all requests to our website to use the HTTPS protocol. We just want to replace the protocol of the URL, the rest of the URI can stay the same. Everything works when we start browsing through the website from the homepage. When we open any other page that isn't the homepage first (i.e. ourdomain.com/this-is-a-page/) we don't get redirected to use HTTPS. What do I need to change on my htaccess file to accomplish this?
This works (it inserts https): ourdomain.com
This doesn't work: ourdomain.com/this-is-a-page/
Thanks!
htaccess code:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
You need to put your redirect rule before your routing rule. The rewrite engine loops so the routing rule (which routes stuff to index.php) gets executed first, the rewrite engine loops, then the second redirect rule gets applied, which redirects the wrong thing. Try:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]