I had my web site in a subfolder and I made a decision to go to the foundation degree of the area.
The largest problem was maintaining all articles on the identical path as a subfolder whereas redirecting the URL to the foundation of the area or another location.
Apache
Apache HTTP server helps RewriteCond
. To make this modification, edit your .htaccess
or httpd.conf
file and add the next strains to it:
RewriteEngine on
RewriteBase /
RewriteRule ^subfolder/(.*)$ /$1 [R=301,NC,L]
Right here we use /
as our base and our RewriteRule
works for all URLs in our subdirectory by utilizing common expressions. R=301
specifies a everlasting redirect.
Nginx
We are able to obtain an identical redirection with the Nginx net server utilizing the rewrite
directive in your /and so forth/nginx/nginx.conf
or /and so forth/nginx/conf.d/default.conf
:
location ^~ /subfolder {
rewrite ^/subfolder(.*)$ $1 final;
}
Right here ^~
modifier ensures that this prefix location continues to take priority must you add regex areas sooner or later.
IIS
In IIS, we are able to use the Rewrite module to rewrite URLs which can be in a subdirectory and we need to appear like they’re within the root. you possibly can your net.config
file in your webroot folder (%SystemDrivepercentinetpubwwwroot
) with one thing like:
<?xml model="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<guidelines>
<rule title="Root_URL_Rewrite" stopProcessing="true">
<match url="^(.*)" />
<motion kind="Rewrite" url="/subfolder/{R:0}" />
</rule>
</guidelines>
</rewrite>
</system.webServer>
</configuration>
You may also use the URL Rewrite UI in IIS Supervisor so as to add an inbound rule.
Cloud Flame
We are able to obtain an identical redirect with Cloudflare by following the steps under:
- Log in to your Cloudflare account.
- Click on on the suitable Cloudflare account for the area you need to add URL forwarding to.
- Click on the Guidelines app, then click on the Web page Guidelines tab.
- Below Web page Guidelines, click on Create Web page Rule. The Create Web page Rule dialog field opens on your area.
- Now below If the URL matches, enter the URL sample for a subfolder that ought to match the rule, corresponding to
https://instance.com/subfolder
. - Then click on Add a setting and select Ahead URL from the drop-down menu.
- Click on Choose Standing Code and select 301 (everlasting redirect) or 302 (short-term redirect).
- Enter the vacation spot URL on your major area and click on Save and Deploy to complete.
The instance above is to redirect the whole lot from https://geekflare.com/weblog to https://geekflare.com
To dam
As you possibly can see, redirecting or mapping a subfolder to root or some other URL is a standard activity and is supported by many of the well-liked browsers with a number of choices.
Then learn how to host a number of web sites on one IP.