.htaccess domain redirect + wordpress

How to enable this:

If I type: maggew.com/abcxyz


you redirect tomr.maggew.com/abcxyz


If I type: maggew.com/privacy


you redirect tomr.maggew.com/privacy


if i type: maggew.com/refund


you redirect tomr.maggew.com/refund


If I type: maggew.com/contact


you redirect tomr.maggew.com/contact


etc..etc ... etc ....

I have used Shared Hosting on 1 and 1 and now I have a digital ocean droplet.
I tried using HTACCESS REDIRECT GENERATOR but didn't have much luck.

Here is my current .htaccess:

# REDIRECTS STORE
redirect 301 /shop http://mr.maggew.com/store
redirect 301 /market http://mr.maggew.com/store
redirect 301 /outlet http://mr.maggew.com/store
redirect 301 /bazaar http://mr.maggew.com/store
redirect 301 /boutique http://mr.maggew.com/store

# PROTECT WP-CONFIG.PHP
<files wp-config.php>
order allow,deny
deny from all
</files>

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

#force subdomain of mr.maggew.com
RewriteCond %{HTTP_HOST} !^mr\.
RewriteRule (.*) http://mr.maggew.com%{REQUEST_URI} [R,L,QSA]

      

+3


source to share


2 answers


Option 1

before you do all the folder specific redirects you need to redirect the domain first
RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://www\.domain.com\/ [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R=301,L]

      

Option 2

If you have old url instances in your content, you can use something like this to update it to the new one. I'm not sure how effective this is.



http://www.wpbeginner.com/plugins/how-to-update-urls-when-moving-your-wordpress-site/

Option 3

or you can use http://wp-cli.org/ to modify your database instances or use mysql command line search and replace.

all your urls from content and links to page links are stored in the database. you can bulk search and replace if you know what you are doing.

+2


source


Assuming you are in the same host and directory structure, you can add a health check for the subdomain to HTTP_HOST, if there is no subdomain you can redirect it.

# REDIRECTS STORE
redirect 301 /shop http://mr.maggew.com/store
redirect 301 /market http://mr.maggew.com/store
redirect 301 /outlet http://mr.maggew.com/store
redirect 301 /bazaar http://mr.maggew.com/store
redirect 301 /boutique http://mr.maggew.com/store

# PROTECT WP-CONFIG.PHP
<files wp-config.php>
order allow,deny
deny from all
</files>

RewriteEngine On
#force subdomain of mr.maggew.com
RewriteCond %{HTTP_HOST} !^mr\.
RewriteRule /?(.*)$ http://mr.maggew.com/$1 [R,L,QSA]

RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

      



Alternative

#force subdomain of mr.maggew.com
RewriteCond %{HTTP_HOST} !^mr\.
RewriteRule (.*) http://mr.maggew.com%{REQUEST_URI} [R,L,QSA]

      

+1


source







All Articles