how to use post or page name as subdomain

 Just a suggestion, you can try using redirects with .htaccess (Apache) or .conf (nginx) to redirect URLs (automatic URL forwarding) to the subdomain.

In nginx:

location = / {
    # don't redirect http://example.com/
}

location / {
    # redirect everything else
    rewrite ^\/([^\/]*).*$ http://$1.example.com/ redirect;
}

Replace redirect with permanent depending if you want a temporary (HTTP 302) or a permanent (HTTP 301) redirect.

The empty location = / block is necessary so that you don't redirect http://example.com/ to http://.example.com/.


//replacing domain name in rewrite rule

location = / {
    # don't redirect $server_name/
}


    location / {
        rewrite ^\/([^\/]*).*$ https://$1.$server_name/ redirect;


From subdomain to domain/page in apache 

Remeber if you are using apache or nginx as proxy remove P tag else will throw error

https://wordpress-hosting.promonsterhost.com/ to https://promonsterhost.com/wordpress-hosting/


RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.promonsterhost.com
RewriteCond %{HTTP_HOST} ^(.+).promonsterhost.com
RewriteRule ^([^/]*)$ http://www.promonsterhost.com/%1 [P,L,QSA]

//Do not add s in http else will throw error


For openlitespeed server

RewriteEngine on
RewriteCond %{HTTP_HOST} !^/?www\.fullform.tech
RewriteCond %{HTTP_HOST} ^/?(.+).fullform.tech
RewriteRule ^/?([^/]*)$ http://www.fullform.tech/%1 [P,L,QSA]


Any requests http://test.example.com will be mapped to http://example.com/test/...


RewriteCond %{HTTP_HOST} ^([^/.]+)\.example\.com$ 
RewriteCond %1 !^(www|ftp|mail)$ [NC]
RewriteRule (.+)$ "http://example.com/%1" [L,P]

Stop redirecting for wp-admin as subdomain in nginx

location ~ ^/wp-admin/(.*)$ {
    # don't redirect $server_name/
}

 location ~ ^/(wp-admin|wp-login\.php) {
  #               # don't redirect $server_name/
  }



Creating subdomain to redirect any page or directory




I want to add subdomain to redirect any sub-directory or page.

For example:
My site: ibrahimmumcu.com
Redirect: kisa.ibrahimmumcu.com to ibrahimmumcu.com/any/subdirectory


simple way to do this is a 2-part solution:

in the .htaccess:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mysite.com
RewriteCond %{HTTP_HOST} ^(.+).ibrahimmumcu.com
RewriteRule ^([^/]*)$ http://www.ibrahimmumcu.com/subdirectory/%1 [P,L,QSA]

in the vhost config, add (below ServerName):

ServerAlias *.ibrahimmumcu.com

You will need to enable .htaccess by changing

AllowOverride None

To

AllowOverride All

This will change allow people to visit

 kisa.ibrahimmumcu.com

and actually get

www.ibrahimmumcu.com/subdirectory/kisa


.htaccess flag list

  • C (chained with next rule)
  • CO=cookie (set specified cookie)
  • E=var:value (set environment variable var to value)
  • F (forbidden - sends a 403 header to the user)
  • G (gone - no longer exists)
  • H=handler (set handler)
  • L (last - stop processing rules)

Last rule: instructs the server to stop rewriting after the preceding directive is processed.

  • N (next - continue processing rules)
  • NC (case insensitive)
  • NE (do not escape special URL characters in output)
  • NS (ignore this rule if the request is a subrequest)
  • P (proxy - i.e., apache should grab the remote content specified in the substitution section and return it)
  • PT (pass through - use when processing URLs with additional handlers, e.g., mod_alias)
  • R (temporary redirect to new URL)
  • R=301 (permanent redirect to new URL)
  • QSA (append query string from request to substituted URL)
  • S=x (skip next x rules)
  • T=mime-type (force specified mime type)

Flags are added to the end of a rewrite rule to tell Apache how to interpret and handle the rule. They can be used to tell apache to treat the rule as case-insensitive, to stop processing rules if the current one matches, or a variety of other options. They are comma-separated, and contained in square brackets.


I have a lot of page URLs like domain.com/page I want a rewrite rule that will change all my pages URLs as page.domain.com meaning whatever will come after the domain just rewrite it as a subdomain

example urls

expertpro.cloud/hot-to-write-blog to hot-to-write-blog.expertpro.cloud

expertpro.cloud/game to game.expertpro.cloud

expertpro.cloud/nibm-full-form to nibm-full-form.expertpro.cloud

expertpro.cloud/choclate to choclate.expertpro.cloud

expertpro.cloud/harmony-in-life to harmony-in-life.expertpro.cloud

expertpro.cloud/paki-cold-places to paki-cold-places.expertpro.cloud

expertpro.cloud/you-are-one to you-are-one.expertpro.cloud

I already have some code for Nginx

             The empty location = / block is necessary so that you don't redirect 
               http://example.com/ to http://.example.com/.


             //replacing domain name in rewrite rule

           location = / {
           # don't redirect $server_name/
             }


          location / {
            rewrite ^\/([^\/]*).*$ https://$1.$server_name/ redirect;


OK, all you need is an internal rewrite, as it looks:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
RewriteRule ^ /%1%{REQUEST_URI} [END]

You obviously need the rewriting module to be loaded into your http server.

That would be a variant which additionally redirects direct requests to the internal URL:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^/?([^/]+)(/.*)?$ https://$1.example.com$2 [R=301]

RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
RewriteRule ^ /%1%{REQUEST_URI} [END]

Here it makes sense to start out with a R=302 temporary redirection and only to change that into a R=301 permanant redirection once everything works as expected.

In general you should try to implement such rules in the actual http server's host configuration. If you have no access to that you can instead use a distributed configuration file (".htaccess"), you need to enable the interpretation of such files in that case.



worked for apache

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?hostingsupports\.com$

RewriteCond %{REQUEST_URI} !^/wp-admin

RewriteCond %{REQUEST_URI} !^/wp-login*

RewriteCond %{REQUEST_URI} !^/wp-json*

RewriteCond %{REQUEST_URI} !^/sitemap*

RewriteCond %{REQUEST_URI} !^/main-sitemap*

RewriteCond %{REQUEST_URI} !^/post-sitemap*

RewriteCond %{REQUEST_URI} !^/category-sitemap*

RewriteCond %{REQUEST_URI} !^/page-sitemap*

RewriteRule ^/?([^/]+)(/.*)?$ https://$1.hostingsupports.com$2 [R=301,QSA,L]


Working for Openlitespeed server


RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?hostingwebsite\.io$

RewriteCond %{REQUEST_URI} !^/?/wp-admin*

RewriteCond %{REQUEST_URI} !^/?/wp-content*

RewriteCond %{REQUEST_URI} !^/?/wp-login*

RewriteCond %{REQUEST_URI} !^/?/wp-includes*

RewriteCond %{REQUEST_URI} !^/?/wp-json*

RewriteCond %{REQUEST_URI} !^/?/sitemap*

RewriteCond %{REQUEST_URI} !^/?/main-sitemap*

RewriteCond %{REQUEST_URI} !^/?/post-sitemap*

RewriteCond %{REQUEST_URI} !^/?/category-sitemap*

RewriteCond %{REQUEST_URI} !^/?/page-sitemap*

RewriteRule ^/?([^/]+)(/.*)?$ https://$1.hostingwebsite.io$2 [R=301,QSA,L]



for Fullform.tech

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?fullform\.tech$
RewriteCond %{REQUEST_URI} !^/?/wp-admin*
RewriteCond %{REQUEST_URI} !^/?/wp-content*
RewriteCond %{REQUEST_URI} !^/?/wp-login*
RewriteCond %{REQUEST_URI} !^/?/wp-includes*
RewriteCond %{REQUEST_URI} !^/?/wp-json*
RewriteCond %{REQUEST_URI} !^/?/wp-cron*
RewriteCond %{REQUEST_URI} !^/?/sitemap*
RewriteCond %{REQUEST_URI} !^/?/main-sitemap*
RewriteCond %{REQUEST_URI} !^/?/post-sitemap*
RewriteCond %{REQUEST_URI} !^/?/category-sitemap*
RewriteCond %{REQUEST_URI} !^/?/page-sitemap*
RewriteCond %{REQUEST_URI} !^/?/bumkailash*
RewriteCond %{REQUEST_URI} !^/?/default*
RewriteCond %{REQUEST_URI} !^/?/xmlrpc*
RewriteCond %{REQUEST_URI} !^/?/robots.txt*
RewriteCond %{REQUEST_URI} !^/?/ads.txt*
RewriteRule ^/?([^/]+)(/.*)?$ https://$1.fullform.tech$2 [R=301,QSA,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Header Set Access-Control-Allow-Origin "*"


# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^/index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress



Always add www in front of domain name in homepage like https://www.sarkarijob.io/

else elementor and page editor like nimble page builder will throw error


For google adsense earning hack 

cookie disappearing in a very short time on homepage change actgion url add www

action="https://www.sarkarijob.io/home.php"


as the cookie will work for www

and to make cookie work further on all subdomains you need to set

 document.cookie = `ul=${fu}`+expiry+'; domain=.sarkarijob.io;path=/';


this line in home.php  change domain value as per need




























Comments

Popular posts from this blog

cpanel exam CPSP Answers

How to install zimbra collaboration suite 8.8.11 on CentOS 7

awstats installation