5

How do I redirect Pages from the main site with 404 Status to the Subdomain with same URL Structure?

This for example:

https://www.example.com/rent

this returns a 404 Error and must be redirected to:

http://subdomain.example.com/rent

Is this possible on WordPress? If it is how can we do it?

  • Firstly, not sure how it is going to help you deal with 404. With custom implementation, it's definitely possible. Logically i would say it's definitely possible. – TopQnA May 17 '17 at 11:03
  • check : gist.github.com/ScottPhillips/1721489 Hope it helps......and yes its possible – smarttechy May 17 '17 at 11:38
  • @TopQnA it is possible with none wordpress site. I have seen the code which is added on the .htaccess. I do wonder how RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d can determine if it wordpress or not. – Alen May 18 '17 at 7:28
  • @TopQnA here is the code but I believe it isn't for wordpress since I have tried it on a wordpress site: stackoverflow.com/questions/12960140/… – Alen May 18 '17 at 7:35
  • 3
    As mentioned in my comment below, if you are using WordPress (or any other CMS for that matter where the content is controlled by a database and not simply on the filesystem) then you can't do this redirect in .htaccess. You will need to do something in WordPress itself - either a plugin or hijack the 404 response/page somehow. – MrWhite May 18 '17 at 8:36
0

There are several ways to add redirects for specific pages to a WordPress blog. There are plugins and extensions to WordPress that will allow redirects. http://www.wpbeginner.com/beginners-guide/beginners-guide-to-creating-redirects-in-wordpress/ recommends two of them.

I would take the approach of editing the .htaccess file and just putting the redirect in there:

Redirect permanent /rent http://subdomain.example.com/rent
-2

Do this in .htaccess file in main subdirectory

RewriteEngine On
RewriteCond %{HTTP_HOST} example.com
RewriteRule ^(.*)$ http://sub.example.com/sub$1 [R=permanent,L]
  • 2
    This simply redirects everything to the subdomain, which is not what the OP was asking at all. (You also have a spurious /sub subdirectory on the substitution.) Unfortunately it's not possible to do this sort of redirection in .htaccess on a WordPress site, since in order to determine if the request results in a 404, WordPress needs to perform some database lookups - this all happens long after .htaccess has handled the request. – MrWhite May 17 '17 at 14:39
  • we are talking about subdomain here not subdirectory. – Alen May 18 '17 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.