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?
Related
I have this web api project which is developed by other company. The file structure is:
/project
---/app
---/ApiEndpoint.php
---/public
---/index.php
The DocumentRoot is pointing to /project/public. The index.php is working (http://myapi.com/), however when I try to browse into the api endpoint http://myapi.com/api/endpoint I got 404 error.
How do I configure the .htaccess to rewrite this condition?
/project/public/.htaccess config
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /index.php?path=$1 [NC,L,QSA]
</IfModule>
The current configuration is there to make sure every request go to index.php (that is probably dispatching requests in some way) except for the files that actually are in the public directory (probably needed for static files like images, and such).
If you wrote a php yourself to be directly called by http://myapi.com/api/endpoint, you should put it in /project/app/public/api/endpoint/index.php.
BUT I suspect you should study that application more and understand the current dispatching method, before doing that.
I've done a search for my question but have yet seen one similar to mine.
I have a newly installed CI on my server, for security reason I have shifted the "application" and "system" folder outside of public_html and into a folder called "app". I tried a lot of methods that the forums were using but none seem to help.
Below is my folder structure, would like to know what to type for the .htaccess and where does this .htaccess go to?
/
app (system and application folder for CI resides here)
public_html (index.php - the one which defines ENVIRONMENT, styles, other htmls and my current .htaccess resides here)
My current .htaccess looks like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
Please help! Thank you for your time!
EDIT
Currently my url is something like this
xxx.xxx.xxx.xxx/~app/index.php/user/check/id
(it's on a shared hosting but not linked to domain yet and hence the ip address and partition in the url.)
I want to achieve something like
xxx.xxx.xxx.xxx/~app/user/check/id
and it should work when I link up my domain. (e.g. www.mydomain.com/user/check/id)
Alright, I think I've solved the problem.
This has most probably got to do with the 'unique' url that I have. I assume if it is a normal domain name it shouldn't have so much problems.
My url > xxx.xxx.xxx.xxx/~app/index.php/user/check/id
My directory structure remains the same >
/app (application and system directories goes here)
/public_html (index.php and .htaccess goes here)
.htaccess code as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~app/ << NOTE the addition
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
In config.php, set
$config['base_url'] = 'http://xxx.xxx.xxx.xxx/~app/';
$config['index_page'] = '';
That's all!
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.
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!
In development mode my symfony admin/backend app can be accessed at http://localhost/backend_dev.php. For production mode, I created a controller php file, admin.php, so now in production the admin application can be accessed at http://www.domain.com/admin.php.
What do I have to do to allow the admin app to be accessed at domain.com/admin or admin.domain.com?
Thanks!
you can open new subdomain an on that subdomain (admin.domain.com) setup virtual host that points to server with your symfony app.
you can look at the full tutorial [here][1].
[1]: http://blog.mirthlab.com/2008/03/04/dynamically-loading-symfony-applications-via-subdomains/ here
You probably are better off putting everything admin like in the admin directory, but you can cheat by using mod_rewrite
RewriteRule ^admin/?$ admin.php [L]
Here are some basic ways you could do it:
Either dump admin.php into a folder called 'admin' in the root of www.domain.com, and rename admin.php to index.php. (Easiest solution)
Of course, this way you have to adjust all relative links in admin.php to one level up (appending '../' to the start of all relative urls should work), as well as all absolute links to reflect the changes.
Regarding your admin.domain.com, you should contact your webhost/domain name provider to setup a subdomain for you.
Or if your webhost allows .htaccess files, you could write a mod_rewrite rule.
i would create a module called admin...then in presumably the index action I would put whatever you had in your admin.php file.
then in your routing.yml file just point yourdomain.com/admin to the admin/index....that way you keep everything within the symfony front controller
Andrew
Make sure your DNS resolves the admin.domain.com correctly, then edit .htaccess in the /web to have mod_rewrite pick up on your subdomain and rewrite requests to admin.php. Optionally rename your admin.php to something less obvious or perhaps do a quick subdomain check inside it as well, or extend the rewrite with a 301 redirect if anyone hits domain.com/admin.php.
The following simple .htaccess works for me:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
# The admin subdomain returns the backend
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^admin\.domain\..*
RewriteRule ^(.*)$ admin.php [QSA,L]
# Check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# No?, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Change domain to your own domain.