I need to redirect my old domain to new domain if request has specific word.
EX:
If request has keyword new
http://www.example.com/new/abc
It will redirects to
http://www.newexample.com/abc
remove new from url and redirect to new domain
I solved this using
RewriteCond %{REQUEST_URI} new
RewriteRule ^new/(.*)$ http://www.newexample.com/$1 [R=301,NC]
Related
We are moving shop.domain.com to new domains. Previously we were handling 3 shops via url now we have separate domain for each shop. So we just need to redirect shop.domain.com to shop1.com by default and we are using other .htaccess rules to redirect old links to shop2 and shop3. So we just want shop.domain.com redirect to shop1.com not its sublinks. We have written other rules for the same. Some of the list is below.
RewriteRule ^heidelberg/?$ https://shop1.com [L,R=301]
RewriteRule ^ludwigshafen/?$ https://shop2.com [L,R=301]
RewriteRule ^mannheim/?$ https://shop3.com [L,R=301]
But when trying to add the below .htaccess rule to above it stops the above rules. I just need base url redirect to shop1.com when website is called not its subruls. For suburls i have separate .htaccess.
RewriteCond %{HTTP_HOST} ^shop.domain.com
RewriteRule (.*)$ https://shop1.domain.com [R=301,L]
I want to forward one specific URL to another one. Tried this:
Redirect 301 "/stellenangebote-berlin" "http://mydomain.de/stellenangebote-in/berlin"
The forward works, but the old URL is appended as parameter like so:
www.newURL/deeplink.php?path=stellenangebote-berlin
This breaks my further routing. How can I prevent the script from adding the old path?
Thanks!
Did you try like below because I'm using the below way in my server and it's working fine.
RewriteCond %{HTTP_HOST} ^OLDDOMAIN\.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.de/stellenangebote-in/berlin [R=301,L]
Or you can try it in one more way like below.This one redirects everything after the domain name on the url to the exact same copy on the new domain url:
RewriteEngine on
RewriteRule ^(.*)$ http://mydomain.de/stellenangebote-in/berlin$1 [R=301,L]
I have a main ssl domain https://www.a.com and a normal addon domain http://www.b.com on the same server. I use this .htaccess rule for a.com to redirect an old page in that website to a new one:
Redirect permanent /my_page.php /my_page
It works just fine. When i access a.com/my_page.php it redirects to a.com/my_page. The problem is that the addon domain b.com has the same page name inside its folder, so when i access b.com/my_page.php it also redirects to b.com/my_page. I need to prevent this redirection for the addon domain.
Note: I have tried to use this redirection rule instead but it didn't work at all:
RewriteRule https://www.a.com/my_page.php https://www.a.com/my_page
And this one too didn't work:
RedirectMatch 301 ^a.com/my_page.php$ https://www.a.com/my_page
After some reading and studying i was able to fix this using the RewriteRule instead. Here's the new code:
RewriteCond %{HTTP_HOST} ^.*a.com$ [NC]
RewriteCond %{REQUEST_URI} ^/my_page\.php$ [NC]
RewriteRule ^(.*)$ https://www.a.com/my_page [L,R=301]
I am able to access my website with random sub-domains like this
abcd.theonlytutorials.com
abc.theonlytutorials.com
etc.theonlytutorials.com/otherpage/otherpage
I have one real sub-domain where my blog is
blog.theonlytutorials.com
Is there any possible way to redirect all my fake sub-domains to root domain except the 'blog' one?
Try adding these rules to the htaccess file in your document root, preferably above any rules that you may already have in there:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.theonlytutorials\.com$ [NC]
RewriteCond %1 !^(blog|www)$ [NC]
RewriteRule ^(.*)$ http://theonlytutorials.com/$1 [L,R=301]
You may look into following URL:
Redirect sub domain to main domain
How can I use htaccess to always ADD a directory immediately after the domain name?
So for example, change requests for
http://domain.com/path-to/file.php
to
http://domain.com/added-directory/path-to/file.php
The context here is that i am migrating a site to a new server, and the domain name is not yet pointed to the new server. But the hosting company provides me with a "temporary url" based on the Shared IP and my account username, so http://216.172.172.211/~myusername/ , but all the paths in all the html are doc-root relative, like /images/logo.png, which translates to http://216.172.172.211/images/logo.png which is wrong. I need it to be http://216.172.172.211/~myusername/images/logo.png .
try adding these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/~myusername
RewriteRule ^(.*)$ /~myusername/$1 [L]
If you want to redirect so that URLs show the ~myusername part in the URL address bar, add an R flag to the square brackets:
RewriteRule ^(.*)$ /~myusername/$1 [L,R=301]
This worked for me perfectly
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/~gye
RewriteRule ^(.*)$ https://%{HTTP_HOST}/gye/$1 [R=301,L]
If an URL comes without the /XYZ
Add https:// at the beginning and /gye/ after the domain.
Testing here really helped: https://htaccess.madewithlove.be/