Problems with default app running on non-standard port

I have created a default app using yiic and configured apache to run this app on port 8088. So my contact form url (working) looks like this: But when I fill this form and press ‘submit’, it redirects me to (discards the port) which obviously doesn’t work because there’s nothing running on port 80 on my machine. If I manually add port number to the url, it successfully displays a flash message “thanks for contacting us”.

Could you please show the view code and the generated HTML code (mainly about the form tag part)?

I didn't change a bit in the generated app - it is all default, except few tweaks of urlManager component:






I need to see the generated HTML code.

Here is the latest entry in the apache access log:

Quote - - [02/Feb/2009:13:44:54 -0800] “POST /site/contact.htm HTTP/1.1” 302 -

So it looks like it does redirect to url which doesn't exist.

Here's the source code of contacts page (really, it's default code, you can see it yourself after running yiic):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" xml:lang="en" lang="en">


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta name="language" content="en" />

<link rel="stylesheet" type="text/css" href="/css/main.css" />

<link rel="stylesheet" type="text/css" href="/css/form.css" />

<script type="text/javascript" src="/assets/84074fd5/jquery.js"></script>

<title>My Web Application - Contact Us</title>



<div id="page">

<div id="header">

<div id="logo">My Web Application</div>

<div id="mainmenu">


<li><a href="/site/index.htm">Home</a></li>

<li><a class="active" href="/site/contact.htm">Contact</a></li>

<li><a href="/site/login.htm">Login</a></li>


</div><!-- mainmenu -->

</div><!-- header -->

<div id="content">

<h1>Contact Us</h1>


If you have business inquries or other questions, please fill out the following form to contact us. Thank you.


<div class="yiiForm">


Fields with <span class="required">*</span> are required.


<form action="/site/contact.htm" method="post">

<div class="simple">

<label for="ContactForm_name" class="required">Name <span class="required">*</span></label><input name="ContactForm[name]" id="ContactForm_name" type="text" value=""/></div>

<div class="simple">

<label for="ContactForm_email" class="required">Email <span class="required">*</span></label><input name="ContactForm[email]" id="ContactForm_email" type="text" value=""/></div>

<div class="simple">

<label for="ContactForm_subject" class="required">Subject <span class="required">*</span></label><input size="60" maxlength="128" name="ContactForm[subject]" id="ContactForm_subject" type="text" value=""/></div>

<div class="simple">

<label for="ContactForm_body" class="required">Body <span class="required">*</span></label><textarea rows="6" cols="50" name="ContactForm[body]" id="ContactForm_body"></textarea></div>

<div class="simple">

	<label for="ContactForm_verifyCode">Verification Code</label>	<div>

	<img id="yw0" src="/site/captcha.htm" alt=""/>	<input name="ContactForm[verifyCode]" id="ContactForm_verifyCode" type="text" value=""/>	</div>

	<p class="hint">Please enter the letters as they are shown in the image above.

	<br/>Letters are not case-sensitive.</p>


<div class="action">

<input type="submit" name="yt1" value="Submit"/></div>


</div><!-- yiiForm -->

</div><!-- content -->

<div id="footer">

Copyright &copy; 2009 by My Company.<br/>

All Rights Reserved.<br/>

Powered by <a href="">Yii Framework</a>.</div><!-- footer -->

</div><!-- page -->

<script type="text/javascript">


jQuery(document).ready(function() {

jQuery('img#yw0').after("<a href="#" id="yt0">Get a new code</a>");

jQuery('#yt0').click(function(){jQuery.ajax({'success':function(html){jQuery("#yw0").attr("src",html)},'url':'/site/captcha/refresh/1.htm','cache':false});return false;});






It looks fine to me. The form action URL is correct which is a relative URL, meaning using the current host info (including host name and port number).

I also couldn't reproduce the issue. Maybe you should check you .htaccess or Web server setup?

.htaccess was copied from yii guide:

Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on

# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php

RewriteRule . index.php

Apache was configured with virtual host for this app:

Listen 8088




DocumentRoot "C:/Program Files/Apache/htdocs/MyTestApp"


What else can I check? Everything works absolutely fine if I change 8088 to 80 and restart Apache. But when I change port back, it stops working with the behavior I described. So between two states (working vs non-working) the only difference is port number (80 vs 8088). All other configuration stays the same.

The problem appears to be with CHttpRequest::redirect which redirects to "" instead of "".

You wouldn't believe that, but here are two $_SERVER variables:



Since CHttpRequest uses SERVER_PORT variable, it redirects to the wrong url. Looks like a bug in Apache or PHP?

I have added the following code to CHttpRequest::getHostInfo method after $port assignment:

if (count($segs) == 2 && $port != $segs[1])

    $port = $segs[1];

Could you please apply this patch to Yii?

I see. Thanks. Fixed.