Create a Subdomain in godaddy hosting using PHP - php

Is there any easiest way to create a sub domain using PHP code on godaddy.com hosting?
e.g:
jon.mywebsite.com
jessie.mywebsite.com
etc

you need to create a A record to serve all your subdomains
*.your-site.com IN A YOUR-IP-ADDRESS
then you need to create a .htaccess file and
RewriteCond {REQUEST_URI} !\.(png|gif|jpg)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?uri=$1&hostName=%{HTTP_HOST}
this will ignore images (SEO friendly URLs).
Now you can redirect your users to $userName.your-site.com
Alternatively try this:
setup your application so your users goes to
your-site.com/user
your .htaccess should look like this
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([aA-zZ])$ index.php?username=$1
RewriteCond %{HTTP_HOST} ^(^.*)\.mywebsite.com
RewriteRule (.*) index.php?username=%1
so now when you hit the index.php it will grab the user and redirect to $user.your-site.com as a custom subdomain. (in this case usernames are limited to a-z characters)

I dont think with PHP Code you can but with the help of .htaccess i think it is possible.
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+jon/
RewriteRule ^jon/(.*)$ http://jon.mywebsite.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} \ /+jessie/
RewriteRule ^jessie/(.*)$ http://jessie.mywebsite.com/$1 [L,R=301]
RewriteRule ^(jon|jessie)/ - [L]
RewriteCond %{HTTP_HOST} ^(www\.)?jon\.mywebsite\.com$ [NC]
RewriteRule ^(.*)$ /jon/$1 [L]
RewriteCond %{HTTP_HOST} ^(www\.)?jessie\.mywebsite\.com$ [NC]
RewriteRule ^(.*)$ /jessie/$1 [L]
You can make subdomain much easier using control panel, why to do it the hard way ?

This is an old question, but in case anyone is looking for the answer. This is specific to GoDaddy, but other Hosts may do something similar to this.
After you setup your DNS A record you need to go to Hosted Domains and add the subdomain folder name under the root domain account.
Go to Hosted Domains.
Under Hosted Domains you will see a root domain table column.
You will also see a Subdomains table column with an "Add" link.
This link is for adding subdomains to a root domain.
Type in/enter the name of the subdomain folder.
Create either an index.php or index.html file and upload it to your subdomain folder and echo something like "Setup Completed". I noticed that if you are doing something like creating a restricted "api" subdomain for example and the GD script cannot access the index file in your subdomain folder then the "process" does not complete until you add a plain index.php or index.html file in your subdomain folder. After that is done then you can add anything you want in that subdomain folder/site.

Related

How to show content of all sub-directory in sub-domain for all my user on the site [htaccess]?

I would show the content of sub-directory in a sub-domain generate with htaccess.
Practically I must create a sub-domain for all user that register on my website
Example of my site web example.com:
/index.php
user1/
user2/
user3/
Obviously the url are now:
example.com/user1/
example.com/user2
etc...
But I would show in the browser user1.example.com, user2.example.com, etc... without change whenever the file .htaccess
Thank you all!
Check this rewrite in top of your .htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ http://example.com/%1/$1 [L]

Multisite Wordpress, SSL and htaccess to use the subfolder as a root

I have an SSL sertificate, so http -> https is a must (as a precaution). I intend to have multiple subdomains, i.e. subdomain1.example.com, subdomain2.example.com, currently there is one subdomain that works without any issues. I'm using a multisite Wordpress setup, that was installed (purposely) in one subfolder. The multisite setup is for other languages. The current server folder layout is as follows:
public_html
backstage
subdomain1 (folder for the subdomain)
frontstage
wp-admin
wp-content
wp-includes
(the rest of the WP files)
index.php (a test file, that shouldn't load if the redirection is set up properly)
Currently, the www.example.com/frontstage/ opens the main WP site, this is fine. I can access its wp-admin without issues. www.example.com/frontstage/en/ shows a 404 page, this is not fine. www.example.com/frontstage/en/wp-admin/ opens the dashboard fine for the other site.
I want to retain the stripping out of index.php from any links (to keep the links clean).
There are two "simple" things to configure properly:
I want to retain the server folder structure as it is, but having the "frontstage" folder skipped, so that when you visit www.example.com, the main WP site loads (and in the case someone would load www.example.com/frontstage/ it would redirect to www.example.com). Naturally, the "shift" needs to allow for the www.example.com/en/ to open the secondary website (any any other language sites that may follow). Ideally without rewriting all the links within the WP sites.
Currently the /en/ site doesn't load its root. The demo posts and pages load fine.
My current .htaccess on the root level looks like this:
# disable index.php from urls
RewriteEngine On
RewriteBase /
<IfModule mod_rewrite.c>
# redirect index.php requests
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
# force https and www
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
# move wordpress one level up
# allow subdomain
RewriteRule ^backstage\/subdomain1\/?(.*)$ "https\:\/\/subdomain1\.example\.com\/$1" [R=301,L]
Any help with this is highly appreciated (I'm still learning the htaccess bits and tricks and this one is truly beyond me). What am I missing in the above code to get it right?
When I have WP installed within a subfolder, I just goto Settings => General and change the Website URL by removing the subfolder.
Afterwards I move the file index.php one folder level up and in your case, would change it to:
require( dirname( __FILE__ ) . '/frontstage/wp-blog-header.php' );
Does this solve your problem?
Find a detailed description how to move WP to a subdirectory on this site - You can find a detailed description about putting Wordpress in a subdirectory on the following website https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
Regarding a redirection from http to https - this is possible within the .htaccess. Much better, in my opinion, would be an alias on the apache (this usually should be done by your hoster).
The difference:
The htaccess redirect goes back to the user and then again to the server, which costs some time. The alias is - as far as I know - redirected on the server.
if you want to force https, you can do it with the following entry.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

htaccess for domain and subdomain with laravel

I'm trying to figure out how to set up a domain and subdomain to work on a shared hosting account. It is a Laravel 5.1 application.
My access file is
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^ index.php [L]
I just purchased another domain and added it on, but I get a 500 error. I renamed the access file and then it worked. So it has something to do with the access file. Essentially I want two separate domains with and I'm wanting two separate laravel applications, one for each.
I'm not familiar with atacceess.
Maybe, you get a redirect loop, because the rule isn't protected by a condition. Although the default htaccess of Laravel should already contain them.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
Olaf Dietsche's answer does work for me.
Here is another thing I came upon a website that also worked just before I saw his post. I guess I was reading that this would send a 404 to that directory.
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^ index.php [L]
RewriteCond %{HTTP_HOST} ^(www.)?main-topdomain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/subdomain-folder/(.*)$
RewriteRule ^(.*)$ - [L,R=404]
So along with this comes another question if anyone is in my boat. I have my subdirectory inside of my root directory.***
dlaugh.com/public_html
laravel folders and access**
inluding
app
bootstrap
config
database
etc...
but also I have my sub folder
app
bootstrap
config
database
etc...
**mysubdomain in that folder**
Is it better practice to put
-main_domain_folder and
-subdomain_folder
in public_html
and then the
/app
/config
/database
would be in the main_domain_folder rather than passing the subdomain through the main domain?

.htaccess to redirect parts of a URL to local files

I have a custom web app and the file structure works like this:
/apps/calendar/frontend/index.php
/apps/calendar/frontend/view/index.php
/apps/calendar/backend/index.php
/apps/calendar/backend/edit/index.php
/apps/calendar/backend/add/index.php
/apps/calendar/backend/view/index.php
I'm trying to write a .htaccess file to help redirect the files so they cant see the 'real' path.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule ^([^/\.]+)/(.*)/(.*)($|/$) /apps/$1/frontend/$2/$3 [NC,L]
RewriteRule ^([^/\.]+)/(.*)($|/$) /apps/$1/frontend/$2 [NC,L]
RewriteRule ^([^/\.]+)($|/$) /apps/$1/frontend/ [NC,L]
When I visit localhost/calendar it should map redirect to /apps/calendar/frontend/index.php. But when I visit localhost/calendar/add it gives me a 301 (permanent move) then shows the full page of localhost/apps/calendar/frontend/add/index.php in the console. Anyone got any ideas why this would happen? Or a better way around this? The apps might have heaps of sub-directories so, I'm not particularly keen on having a rule for ever subdirectory combination.
As you can see also I have a /admin path, which would load the /backend/ parts of the app. I would assuming I can do the similar code with the prefix of /admin?
This question might also be of your interest: Create blog post links similar to a folder structure.
Given that your .htaccess is located on the root folder of your domain /home/youraccount/public_html/.htaccess, it would look like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(admin|apps) [NC]
RewriteCond %{DOCUMENT_ROOT}/apps/$1 -d
RewriteRule ^([^/]+)/?(|.*)$ /apps/$1/frontend/$2 [NC,L]
RewriteCond %{REQUEST_URI} !^/apps [NC]
RewriteCond %{DOCUMENT_ROOT}/apps/$1 -d
RewriteRule ^admin/([^/]+)/?(|.*)$ /apps/$1/backend/$2 [NC,L]
Let's say the user access:
http://domain.com/calendar
http://domain.com/calendar/
http://domain.com/calendar/add
All the above would redirect to
/apps/calendar/frontend/index.php
/apps/calendar/frontend/index.php/
/apps/calendar/frontend/index.php/add
And the if the user access:
http://domain.com/calendar/admin
http://domain.com/calendar/admin/
http://domain.com/calendar/admin/add
It would go to:
/apps/calendar/backend/index.php
/apps/calendar/backend/index.php/
/apps/calendar/backend/index.php/add
So it would make index.php your controller for each end:
/apps/calendar/frontend/index.php
/apps/calendar/backend/index.php

htaccess rewrite sub directory

I have a production copy and a test copy of my website on bluehost. Each website is in it's own directory in public_html folder, one named prod another named test. According to bluehost knoweldge base here: https://my.bluehost.com/cgi/help/347 you setup an htaccess file to rewrite requests coming into the public_html folder to my prod folder. This works pretty well thus far. Something I noticed recently though was with these rewrite settings that if you attempt to load a website file from another directory inside the main website folder e.g. /prod/testfolder without a forward slash on the end it will redirect you to www.mysite.com/prod/testfolder/ instead of staying on www.mysite.com/testfolder. This condition does not happen if you specify the extra forward slash like so.... www.mysite.com/testfolder/
Here is my rewrite rules:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !^/prod/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /prod/$1
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^(/)?$ prod/index.php [L]
I'm not an expert when it comes to rewriting urls using htaccess however I suspect the first chunk of rewrite rules is the cause of this. BTW an example of why this makes a difference is that I setup a blog on this site and if you attempt to visit the blog at www.mysite.com/blog it redirects to www.mysite.com/prod/blog/ which defeats the purpose of using htaccess to mask the prod folder in the first place. Can anyone tell me how I should go about fixing this and maybe explain why it's happening? Thank you!

Categories