Cannot get Yii urlManager to work - yii

I am asking this after a couple of hours of searches. I just can't tell what I am missing here. I am trying to set friendly URLs for my Yii application.
My base url is http://www.baby-registry.org/BABYREG/app/
I am trying to change this url http://www.baby-registry.org/BABYREG/app/index.php?r=generalProducts/admin into http://www.baby-registry.org/BABYREG/app/productAdmin
Using this in my main.php config file:
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
),
),
Either with or without rules (tried different rules I found on stackoverflow), this breaks my app altogether, I get the famous notice 'Congratulations! You have successfully created your Yii application.
You may change the content of this page by modifying the following two files:......'
What am I doing wrong?
Does it have anything to do with the fact that I have a base url like (BABYREG/app)?

You will need to post a bit more code, and also what error message (if any) you are getting.
But, a common reason for the URL rewriting not to work in Yii is that the apache module mod_rewrite is off. This apache module is required to use the Yii URL rewriting.
To check whether this module is enabled, in PHP, use apache_get_modules(); This will return an array of enabled apache modules. So a simple way to check if mode_rewrite is enabled is:
if (in_array('mod_rewrite', apache_get_modules())){
// mod_rewrite is enabled
}
If it is not enabled, ask you hosting company to enable it for you. If you are working on your local host (with WAMP), simply enable it by clicking it under the apache menu - modules in the WAMP icon on the system tray

I just spent way too long with my array arguments reversed. Here's my first successful rewrite:
Link in app:
<a href='<?php echo Yii::app()->createUrl("home"); ?>'>Rewriting test</a>
PHP config:
'rules'=>array('successfully/rewritten' => 'home');
Note that it's desired url and then existing url. Backwards, in my head - I'd reckon it's "rewrite this, to this". Instead, it's "this is the rewrite for this." ^_^

Related

smarty migration website doesn't work. Error 500

I've got to transfer a website from an hoster to another (MelbourneIT).
So I've done as usual with my favorite FileZilla, just copy the html website (without DB) to the other url.
So this one work for the first page ( http://www.lmhceramics.com/) because it's an html one but all my other pages doesn't work!
I've check the folders of my website and I found that this one worked with "Smarty" who is apparently a third party application.
I tried for 5 hours different things as : create an .htaccess to launch index.php instead of index.html, change the configuration on my site_globals.php but it didn't work. It looks like only the first page : index.html is loading.
I can give the access to the ftp if anyone could help it will be sweet as it's one website of my company!
Thanks guys.
Cheers
Initially I tested whether PHP was working, then when I was sure I looked at the error log. The overriding issue was a required library not being found because of a broken path, and PHP's display_errors setting was disabled so it resulted in a white screen.
The site main pages now function.
In site_globals.php, there were two paths that begun with a forward slash. This results in the code looking in the root directory of the server for a particular folder of files (the Smarty library, and the Smarty templates), which likely worked on the old server but not on the new shared hosting environment. New code italicised:
define( "SMARTYPATH", _$_SERVER['DOCUMENT_ROOT'] ._ "/deldridge_smarty/" );
define( "TEMPLATEPATH", _$_SERVER['DOCUMENT_ROOT'] ._ '/smarty/' );
Once that was fixed the code library and templates could be loaded and the rest of the configuration file continued to load. It then dies on:
$db_interface = new DBInterface;
$db_interface->connect( '172.20.254.1' , 'ampnet', 'cable05' );
This is an attempt to connect to a database. I haven't investigated what the database was for yet (that'd require looking through the PHP files in depth) but I'm assuming it was the login system or some such. Almost all of the pages in the site function with those two lines commented out, which I've done for now so that the majority of the content is available again. There's another reference to database connection details further down but they were already commented out.
One other area of particular interest is this:
// different dir structure on secure domain, make ammends
// ensure trailing slash if directory present
define( "SECURE_DIR", 'buildersbollards/' );
if ( $_SERVER['DOCUMENT_ROOT'] == '/home/deldridge/secure.4mation.com.au' )
{
$site_path = '/' . SECURE_DIR;
}
Hop that helps!
It's difficult to know with so little information. Enable error reporting in php or just look at the php error log in your server. One probable cause for the error 500 may be that some key folders don't have CHMOD permission to write; In smarty, for example, templates_c must be writable

APACHE VirtualHosts configuration for Zend project and regular sites

I have such a problem:
In a local network I have a server which is called by its server_ip.
I have few sites located under /www/site_folder where index.php is located.
So whenever http://server_ip/site_folder is called index.php is called and selected site loads.
Now I put in /www/zend_site a Zend project.
It means two things:
1. index.php is located under /www/zend_site/public,
2. Zend requires rewriting rules set up so framework can understand controller/action extracted from an URL.
What I want, and can't succeed, is to have ability to call Zend project by typing http://server_ip/zend, and also to have rest of my simple sites working by calling them by http://server_ip/site_folder.
I got familiar with configuration for a Zend http://files.zend.com/help/previous-version/Zend-Server-5-Community-Edition/configuring_zend_framework.htm and tried to make use of virtual hosts by introducing new one called zend.
I see it's not possible to get such two existing options running. If zend is in virtual host and if I call only sever_ip it loads zend project instead of /www/index.php (a dummy site). If I remove virtual host after I call http://server_ip/zend it loads /www/zend/index.php instead of /www/zend/public/index.php and also site doesn't work (after I created symbolic link to proper index.php), because links are not correctly rewritten with controller/action extraction.
Or maybe I am thinking wrong about VirtualHosts idea? In server_ip/something <- something is not a domain which could be used in VirualHost in this case?....
Any idea if my configuration could work?
Regards

How do I rewrite URLs with Nginx admin / Apache / Wordpress

I have the following URL format:
www.example.com/members/admin/projects/?projectid=41
And I would like to rewrite them to the following format:
www.example.com/avits/projectname/
Project names do not have to be unique when a user creates them therefore I will be checking for an existing name and appending an integer to the end of the project name if a project of the same name already exists. e.g. example.project, example.project1, example.project2 etc.
I am happy setting up the GET request to query the database by project name however I am having huge problems setting up these pretty url's.
I am using Apache with Nginx Admin installed which mens that all static content is served via Nginx without the overhead of apache.
I am totally confused as to whether I should be employing an nginx rewrite rule in my nginx.conf file or standard rewrites in my .htaccess file.
To confuse matters further although this is a rather large custom appliction it is build on top of a wordpress backbone for easy blogging functionality meaning that I also have the built in wordpress rewrite module at my disposal.
I have tried all three methods with absolutely no success. I have read a lot on the matter but simply cannot seem to get anything to work. I am certain this is purely down to a complete lack of understanding on with regards to URL rewriting. Combined with the fact that I don't know which type of rewriting should be applicable in my case means that I am doing nothing more than going round in circles.
Can anyone clear up this matter for me and explain how to rewrite my URLs in the manner described above?
Many thanks.
If you are proxying all the non static file requests to Apache, do the rewrites there - you don't need to do anything on nginx as it will just pass the requests to the back end.
The problem with what you are proposing is that it's not actually a rewrite, a rewrite is taking the first URL and just changing it around or moving the user to another location.
What you need actually takes logic to extrapolate the project name from the project ID.
For example you can rewrite:
www.example.com/members/admin/projects/?projectid=41
To:
www.example.com/avits/41/
Fairly easily, but can you map that /41/ in your app code to change it to /projectname/ - because a URL rewrite can't do that.

How to use relative URL's in website with two base URL's

I have our basic corporate static html website installed in our web root directory and our billing software installed in /portal. I have integrated the websites to look like a single site by including the /menu.tpl smarty template file in the /portal/header.tpl file. However, if I use relative URL's, the menu sysem doesnt work as the base url for the billing script is /portal. i.e. if I create a link to faq.php in the menu.tpl and I load a page on the portal site, the link in the menu back to the faq page is now /portal/faq.php whereby if I load a page off the root site the link is just /faq.php as it should be.
The obvious answer is to just use absolute URL's, but I need the site to be portable as I have many developers who need to install and test it.
I cant find anyway to resolve this. Any ideas?
I ran into the same problem as you a while ago, and after trying a lot of dead ends, I finally ended up with the following solution:
For any URL you need to be a chamelion, i.e. change its path depending on the environment, insert a PHP function that writes out the correct URL.
If you include the PHP function from a single central file, then you can change all of the URL's in the entire site automatically, based on a setting, or some pre-detected switch such as the current domain name, etc.
Example:
<?php print_base_url_plus("/menu.php"); ?>
... where print_base_url_plus() is a function which appends the base URL onto the output.
You may find that you have to change some of the URL's to be php, so they are preprocessed by the PHP engine, or, you can alter the web settings so that standard .htm files are piped through the PHP engine, just like .php files.

Weird apache behavior when trying to display urls without html extension

I have a url that is easily accessible when you request it as:
http://example.com/2005/01/example.html
or
http://example.com/2005/01/example
(I actually don't know why it works without the extension. Instead, it should return the usual 404 error.)
However, when I try to access the following url:
http://example.com/2005/01/example/
(note the trailing slash)
I get a 404 Not found error but with the requested url printed as:
http://example.com/2005/01/example.html/
So, it seems the ".html" part was automatically added by apache.
My question is: how do I disable this behavior? I need to do it because I want add mod_rewrite rules to hide the html extension, so that I can access that url as:
http://example.com/2005/01/example/
My apache is 2.2.9 on Ubuntu 8.10.
Thanks!
MultiViews could cause this behavior. Try to disable it:
Options -MultiViews
Is example.html an actual file that lies in the directory path 2005/01? It seems like mod_rewrite is already active. If you use a blog or content management system on your server, then it probably does stuff to your url's already.