Redirect htaccess

I need to help with redirect my page.

For example I have websites https://example.com. I need to move content from https://example.com to https://example.com/blog. That is not problem and I do that with a change home_page URL. That work pretty well. But Now I need to add redirect from old https://example.com to https://xmpl.com. I want to do with .htaccess but that does not work. Can you help me guys?

Here are some of my attempts of this but both does not work.

RewriteEngine On
RewriteRule https://example.com/ https://xmpl.com/ [L,R=302]

or

RewriteEngine On
Redirect 302 https://example.com/ https://xmpl.com/

Thank you for your help and time guys.

EDIT: That does not work means that this rule does nothning.

Example:

I have site https:// example.com and i changed homepage url to https:// example.com/blog and in .HTACCESS I added the rule. Result of this is that when I go on https://example.com I get https:// example.com/blog instead of new domain https:// xmpl.com

Topic home-url site-url url-rewriting htaccess redirect Wordpress

Category Web


First off, most of the following is speculation, since there are a few details that are unknown. What's happening when it doesn't work? Anything? Nothing?

Also, are you trying to redirect only the home page or have you moved the whole site to this new domain name?

If you are trying to point everything from https://example.com to the new domain (for example, https://example.com/blog will also redirect to https://xmpl.com/blog) you can do this:

Redirect 301 / https://xmpl.com/

The 301 error says everything has been permanently moved to the new site. The first param "/" says "everything at the current url" the second param says "this new domain". (Remember the www matters! https://xmpl.com is not the same as https://www.xmpl.com)

If it is only the home page you want to redirect - so https://example.com/blog should still go to https://example.com/blog, BUT https://example.com should go to https://xmpl.com you can use regex:

RedirectMatch "^/$" "https://xmple.com"

This will match only for the domain root and send it to the new url. Again, www matters. See more helpful regex/mod-rewrite stuff here: https://cheatography.com/davechild/cheat-sheets/mod-rewrite/

Also helpful to know: For the redirect parameters,the first path (to the old file) must be a local path, NOT the full path. So if your .htaccess file is in the directory /example.com, you would not include /home/username/example.com in the local path. The first / represents the example.com directory. If the old file was in that directory, you would follow the / with the old file name. The second path references the new file you want to land at. In your case, the second path is going to be a full URL, referencing a place on a different server, but (for future reference) it can also be a local path.

I hope this helps!

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.