Deployed Yii app don't build url properly to domain subfolder - php

EDIT (a solution):
In the end, the problem wasn't with yii configuration or with the virtual server, but with the main server. I contacted the server administrator and the issue was solved by changing the URL to which the main server (where mi virtual server is hosted into) redirects the requests, to append the string containing the virtual folder's name.
I'm not sure if this was the best solution, but it's a solution. So if you face a similar problem, you might want to contact your server administrator.
Here's the detail of the original problem and some of the options I tried, just for reference:
I've been developing a Yii application for a couple of weeks, and it works perfectly on my local server, but I'm having some troubles to make the URLs work properly when deploying the app.
In the server, I have an structure similar to this:
/www/MyApp/(index.php, protected folder, etc)
/www/yii (the framework is located here)
And I can access my website using an URL like this:
www.somedomain.ac/VirtualFolder/MyApp
My problem is that all the links generated by yii are pointed to (for example):
www.somedomain.ac/MyApp/index.php?r=controller/index
instead of
www.somedomain.ac/VirtualFolder/MyApp/index.php?r=controller/index
I tried modifying the urlManager section at the configuration, and for some reason adding these rules:
'../../VirtualFolder/MyApp/index.php/'.'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'../../VirtualFolder/MyApp/index.php/'.'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
make some of the builded URLs point to the proper action, with the complete URL, but still, other ones won't work (all the ones that send a form to the server).
I've been trying other solutions to similar problems during a couple of days (like changing the app's basepath, adding "VirtualFolder" to it) but they don't seem to work.
Suggestions on how to solve the problem will be very appreciated.
Thanks.
============================================
EDIT: I am trying to do it with an .htaccess file like this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} somedomain.ac$ [NC]
RewriteCond %{HTTP_HOST} !VirtualFolder
RewriteRule ^(.*)$ http://somedomain.ac/VirtualFolder/$1 [R=301,L]
And I copied it to my web root, but not working yet. Also tried copying it to MyApp/protected folder and directly into MyApp. Am I missing something?
Thanks.

You should try to add RewriteBase directive to .htaccess file

(how the problem was solved): In the end, the problem wasn't with yii configuration or with the virtual server, but with the main server. I contacted the server administrator and the issue was solved by changing the URL to which the main server (where my virtual server is hosted into) redirects the requests, to include the string containing the virtual folder's name.
So if you face a similar problem, you might want to contact your server administrator.

Related

http://example.com/portal/p/Logon/ not working after migration (Apache, php)

I have migrated a dynamic website (php, mysql) to a new host on a shared server plan.
The site is fully dynamic and has no fixed paths as such apart from the single entry point file "portal.php". The site exists as path-info to portal.php and is created from templates in a mysql database. There is no /portal directory, for example.
The homepage loads fine, but not subpages.The pathinfo is returned correctly, but the webserver is not translating it I guess:
http://example.com/portal/p/Logon = Fails with 404 error
http://example.com/portal.php/p/Logon = Works!
I have limited control over the apache server as the client has a basic, shared server plan.
I tried various options in a .htaccess file at the root of the website directory, but the best I could do was get an internal 500 error. At least I know the .htaccess is being read.
I'm hoping I can resolve this, otherwise I will have to migrate the site to a dedicated server instead.
Ok I found a solution. I see now why my initial post lacked information :)
I read this guide:
https://httpd.apache.org/docs/current/content-negotiation.html
And after trial and error, the following worked with a .htaccess file placed at root (I modified a html5boilerplate .htaccess file):
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteRule ^portal/(.*) /portal.php/$1
RewriteRule ^portal$ /portal.php

migrating htaccess from localhost WAMP to godaddy subdomain

First off this is similar to other stack questions however none of the solutions helped me. so before your mark as duplicate, or whine about the question try look for solutions and not problems with the question.
Hi all, here's the scoop, I have tried to be thorough.
I have a site that is in mid development.
A potential employer wants to check out the site in its current state.
In order to do this I had to put it as a sub domain of a site I already have hosted with GoDaddy.
the site uses pretty urls that link to php scripts in various directories.
mysite.com/location
would, via htaccess rules go to a script at
mysite.com/src/script/php/location/location.php
or another example might be
****mysite.com/location/fj83jfd83****
would, via htaccess rules go to a script at
mysite.com/src/script/php/location/location.php?item=fj83jfd83
my htaccess file works on my local WAMP stack but not once on the remote goddady server hosted with linux cpanel
my htaccess file is as follows
RewriteEngine On
RewriteBase /
AddDefaultCharset utf-8
RewriteRule ^location/([A-Za-z0-9]+)/?$ src/script/php/location/location.php?item=$1 [NC,L]
RewriteRule ^location$ src/script/php/location/location.php [NC,L]
Question one
I am wondering what changes do I need to make to the htaccess file for this to work on the GoDaddy server on a subdomain like mysite.hostedsite.com?
Question 2
would the htaccess go in the base public root folder or the subdomain root folder?
Couple things to note.
I am open to options that don't use htaccess or another work around that hasn't occurred to me.
This is only for someone to view the site, so a short term patch(hack) solution is fine, the site is not ready for launch.
thanks you in advance
All I needed to do was add the subdomain to the start of the rewrite rule.
so
RewriteRule ^location$ src/script/php/location/location.php [NC,L]
needed to be
RewriteRule ^mysite/location$ src/script/php/location/location.php [NC,L]
just left it encase it helps any one in the future!

Codeigniter, routing is not functioning on production server

I have 3 servers, a localhost apache server, a testing remote server and the production live server.
I have the same installation of codeigniter and site set-up on all 3 of them and on the localhost and testing servers routing without 'index.php' works 100%. On the Production server however, no matter what the URL says only the homepage (via the default controller) will be shown, it seems all routing rules are being ignored except the default one.
If however index.php is added in the URL then it will work like it supposed to.
For instance if the URL on the production site is: 'www.mysite.com/information' then the content that loads is form the default controller.
But when the URL on the production site is: 'www.mysite.com/index.php/information' then the content that loads is from the 'information' controller.
This is the contents of my htacess file: http://pastebin.com/cDaZVJ8A
This is my routes config file: http://pastebin.com/7Ewc2bwN
My $config['index_page'] is set to nothing.
I really dont know why its not working, the same setup on all servers in term of codeigniter itself, and mod_rewrite IS working on the production server.
I don't know what to do, how can I find-out what's wrong?
This is quite a common problem that often occurs when people move a codeigniter install from one environment to another. I have no idea why it occurs, could be a difference in server OS or apache settings, but the solution is often to add a question mark ? to the RewriteRule for the index.php in your .htaccess file.
Old:
RewriteRule ^(.*)$ index.php/$1 [L]
New:
RewriteRule ^(.*)$ index.php?/$1 [L]
Check your Apache virtual host configuration and verify that you have AllowOverride All in your directory definition.
Maybe something is wrong with your .htaccess file?
Once I had problem when I moved application to production server, because RewriteBase was set to some directory on development server.
On my production server application was in web root directory, so RewriteBase should be /, and i had /something there.
Once i had silly problem with upper/lowercases, when i moved site from development server (windows) to production (linux).
I had the same problem. I was using function to convert article names to URL's (slugify).
On localhost and on server this function returned slightly different urls.

Prefix of my domain is messing things up... How do I resolve this?

I am writing a Facebook app and for it to work properly, I need to set the Site URL inside the Application settings. The problem is that if I set my Site URL to be
domain.com
it works on my system and a bunch of systems that I tested it on. Some of my friends complain that it is not working on their system. When I looked at what the error was, it was sending me back this:
Given URL is not allowed by the Application configuration.
which is telling me that the referrer URI that I am sending it is not what it is expecting in the Application settings. So what I did was I changed the URL to:
www.domain.com
and now my friends are able to use the application and it is failing to load on my end. Does anyone know how to fix this issue? Both cases, I tested it on Windows and Ubuntu with the same browser version yet I am seeing this problem and I don't seem to understand why this is happening.
Ok I am not a fan of this solution myself but consider this a hack... This really should be fixed on Facebook end :(
Step 1: In the Facebook Site-URL field of your application just put www.domain.com
Step 2: Create a .htaccess file in the app directory and put the following text in it:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]
Hope that helps someone with the same behavior.

How to make website unavailable for others while developing it online?

Is it possible to make the website unavailable while editing it, while online?
If so, what is the method called and how is it done?
I have a webhosting company so it's not my own server!
Typically, people use the .htaccess to password protect it until you are ready to show it to the world
Here is a link to an article with instructions
http://www.elated.com/articles/password-protecting-your-pages-with-htaccess/
I had the same issue, I just put up a "coming-soon.html" page and redirected everyone without my IP there via htaccess, here's the question on SO: Want to redirect all visitors except for me [.htaccess]
Or, if it's ASP.Net - place a file called app_offline.htm in the site root.
If you are uploading a new version of the site you can create a symlink in the place of the root directory and then switch that when the site's ready. You can also switch the symlink back to the previous version if something goes wrong.
You can make an .htaccess file like this :
RewriteCond $1 !offline.html$
RewriteCond %{REMOTE_ADDR} !^your_ip_adress
RewriteRule ^(.*)$ http://www.mydomain.com/offline.html [R=302,L]
Simply put the files in a new directory and don't tell anybody else the name of the directory. (Or you can tell it to some beta testers if you like.)
When the pages are ready and tested, just move the files into the normal place (after moving the old existing files into backup directory). This way, you always have a working site online.
But generally, it is better to develop the web site on your local computer, not online.

Categories