Vue.js router on a shared hosting plan? - vue.js

I deployed a simple Vue.js website to a shared hosting plan. The website consists of a few internal links that use the router. Links such as /contact or /about.
I read that I need to use a .htaccess on shared web hosts so the router can navigate between its paths. Indeed, I added this code in the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
One thing I noticed is that the router can navigate between its internal links, for example if I'm on the www.domain.com and click on the contact link, it goes to www.domain.com/contact and the page opens up.
However www.domain.com/contact doesn't exist in reality because if I type it out manually in the browser's address bar (without accessing it via a link on a page), then I get a page not found error. That sucks because Google probably won't be able to index my page then.
Is there any way to fix that?
The server is also running PHP. It has a PHP website on it beside the Vue.js one. I think I will need to touch the .htacess in the root folder instead of the one in Vue.js's dist folder.
The .htaccess in the root folder (the one in the root domain) looks like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Is there a way not to remove those? but also add the Vue.JS rules?

Related

Can't get rewrite to redirect all to front controller

I'm trying to redirect all site traffic to my front controller, but I've been having trouble with it getting my site to redirect when the file already exists. For instance: www.example.com/IDontExist/ doesn't exist and sends me to the controller, but www.example.com/maintence/ exist and therefore skips my controller entirely. Not the intention.
I've tried a couple of things in .htaccess files, and I need to use them because I have to upload it to a Godaddy Shared Linux Server, and don't have much access to higher class configs.
This is my current .htaccess file:
RewriteEngine On
DirectorySlash Off
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*)$ /index.php [NC,L,QSA]
</IfModule>
I need to send people going to www.example.com/maintenance/ and all other urls to the front controller to get the page processed before sending it off to the client. Right now it's finding the file and loading that up before going to the front controller.
Edit: Forgot removing RewriteCond commands for some reason result in a 500 error.
Remove your file and directories excludes, after that
RewriteEngine On
RewriteRule ^([^?]*)$ /index.php [NC,L,QSA]
It was a redirect loop. Removing the conditions and then adding the following one would fixed it.
RewriteCond %{REQUEST_URI} !/index.php

Incorrectly configured htaccess file that should direct to subdirectory

I've got a CMS installed in a sub-directory of my webspace and I'm having a little trouble figuring out how to configure the htaccess file.
mysite.com contains a splash page that should stay there for now. The idea is that mysite.com/dev should open the index page of the CMS. I suppose I could go with a subdomain but I'll have to research what to do in this case. Either way all of this is just temporary so whatever works is good.
You can see from the below code I've been messing around and I've commented out a lot of stuff. (I've also not bothered to copy more that I think is probably nonsense.)
#Display PHP Errors
php_flag display_errors Off
RewriteEngine On
RewriteBase /
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^www\.mysite\.com\dev [NC]
# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dev/index.php?q=$1 [L,QSA]
I should note that I'm with a hosting company any my root path is something like
/content/hosting/l/u/mysite.com/web
I've tried to add this (and truncated versions) to my htaccess file but without success.
If dev is your CMS and you want site/dev to open index.php in dev, your htaccess file for dev only needs this line:
DirectoryIndex index.php

Symfony2 htaccess mod rewrite issue

I've been having this issue for quite some time. Right now we are using a shared hosting plan and have four domains, one of which points to a symfony project. My goal is simply to omit having the app.php included in the URL. Without any .htaccess applied, all domains work flawlessly and when trying to navigate to the symfony domain I simply get a directory listing instead of having the page render, unless I include the app.php in the URL.
When applying the below htaccess, all non-symfony related domains show a 500 error and the one symfony related domain renders successfully, without the app.php in the URL. My goal at this point is to modify the htaccess so that all non-symfony related domains render successfully as they did before, while still maintaining the below .htacces to omit the app.php from the Symfony related project.
I appreciate any suggestions on how to resolve this issue. Thanks in advance!
.htaccess
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^app.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
Replace the line :
RewriteCond %{REQUEST_FILENAME} !-f
With :
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]

Yii framework: Using htaccess for site in sub directory not working on Hostgator

I'm trying to set up Yii site to be loaded from sub directory to root domain. In my root site folder I have only root .htaccess file and sub directory "subdir" which contains Yii site. I found a solution that works on my local environment:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) subdir/index.php/$1 [QSA,L]
But when I upload the site to HostGator it just does not work correctly
For example
if I use http://localhost/contact on my local environment, correct page is opened (called site/contact - site controller and contact action. I've added Yii 'contact'=>'site/contact' rule to the urlManager, so both http://localhost/contact and http://localhost/site/contact can work)
If I use http://mydomain.com/contact or (http://mydomain.com/site/contact) on HostGator, I get default index page (called site/index - site controller and default index action instead)
When I choose to access subsites directly like http://mydomain.com/subdir/contact it works fine, but it does not work if I use http://mydomain.com/contact
I guess that I need somehow to change this last rule in htaccess, but not sure how. Thanks!
I've found alternative solution that works. I was forced to use old fashioned URLs instead of paths, so I've changed my urlManager to:
'urlManager'=>array(
//'urlFormat'=>'path',
'showScriptName'=>true,
'caseSensitive'=>false,
'rules'=>array(
...
)
)
And my root htaccess looks now like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdir/index.php?r=$1 [QSA,L]
So, when accessing
http://mydomain.com/site/contact
Actual mapped URL is
http://mydomain.com/subdir/index.php?r=site/contact
which as result returns correct contact page
Since, you stated in your previous question that www.mysite.com/mysite/frontend/www/controller/action works fine; you should be using:
AddHandler application/x-httpd-php53s .php .html
Options +SymLinksIfOwnerMatch
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteCond %{REQUEST_URI} !^/mysite/frontend/www
RewriteRule ^(.*)$ /mysite/frontend/www/$1 [L]
You dont need to edit .htaccess. You just need to move the Yii entry script (index.php) and the default .htaccess up from the subdirectory to the webroot (so that they reside directly under public_html). Once you move index.php and .htaccess to the root directory, all web requests will be routed directly to index.php under webroot (rather than to the subdirectory), thus eliminating the /subdirectory part of the url.
After you move the files, you will need to edit index.php to update the references to the yii.php file (under the Yii framework directory) as well as the Yii config file (main.php). Lastly, you will need to move the assets directory to directly the webroot, since by default, Yii expects the assets directory to be located in the same location as the entry script).
That should be all you need to do, but if you need more details, I describe the approach fully here:
http://muhammadatt.tumblr.com/post/83149364519/modifying-a-yii-application-to-run-from-a-subdirectory

mod-rewrite to ignore the subdomain

I'm using a mod-rewrite for pretty URLs, meant to run on the domain root. Working fine but now I'm trying to make it run on a subdomain and it keeps giving "500 Internal Server Error".
The subdomain automatically redirects to the folder with that name on my hosting account (sub.domain.com shows the content of domain.com/sub/). Does it fail because this request is already being mod-rewritten automatically or can I simply change something in the htaccess to address the subdomain instead?
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Contact your ISP and check if they are setting the DocumentRoot for the sub domains to the /domain/sub/ directory (it's probable) or alternatively using an internal RewriteRule to direct traffic to that directory (you can see if there's an external rewrite / redirect in place via Chrome or Firefox + firebug, use the developer tools to check the response header, on the network Tab). If they have set the document root you will need to copy or symbolically link ALL the files you want accessible via the sub-domain, to the /domain.com/sub/ directory e.g. the .htaccess, index.php, images, js and css files and sub directories. If they are using an internal rewrite, a quick tweak to your own existing internal rewrite, in the existing .htaccess file, should suffice e.g.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]