Jump to content

[SOLVED] non-www to www when all pages being routed through index.php


sKunKbad

Recommended Posts

I'm trying out the kohana framework, and it routes or rewrites all traffic through index.php. This however isn't seen in the browsers address bar. I need to set up my .htaccess to convert non-www urls to www. This was easy in the past, but this framework has mixed things up a bit.

 

Right now, I've got all pages except for the home page doing what it is supposed to. I'm just not sure how to tell apache to rewrite the url for the home page. This is what I have:

 

RewriteRule .* index.php/$0 [PT,L]
RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com [NC]
RewriteRule ^(index.php)?/(.*) http://www.mywebsite.com/$2 [R=301]

 

So, any page other than the home page is converted to www.

Link to comment
Share on other sites

Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com%{REQUEST_URI} [L,R=301]
RewriteRule .* index.php/$0 [PT,L]
</IfModule>

 

You have to put the www rule before the other, because the [L] told to stop parsing the .htaccess and use this rule.

 

You don't have to worry about the www rule with a [L] because the .htaccess will be called twice if the domain isn't www.mysite.com, it will be redirect using a 301 and reparsed with the new URL.

Link to comment
Share on other sites

Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com%{REQUEST_URI} [L,R=301]
RewriteRule .* index.php/$0 [PT,L]
</IfModule>

 

You have to put the www rule before the other, because the [L] told to stop parsing the .htaccess and use this rule.

 

You don't have to worry about the www rule with a [L] because the .htaccess will be called twice if the domain isn't www.mysite.com, it will be redirect using a 301 and reparsed with the new URL.

 

I just get "Internal Server Error" when I try this

Link to comment
Share on other sites

Here is the whole doc if it matters

 

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
# RewriteRule ^(.*)$ http://www.mysite.com%{REQUEST_URI} [L, R=301]

# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^google2d216fed8ww53492f.html [NC]
RewriteCond %{REQUEST_FILENAME} !^y_key_8b37d87ae82wwr07b3e.html [NC]
RewriteCond %{REQUEST_FILENAME} !^robots.txt [NC]
RewriteCond %{REQUEST_FILENAME} !^current-projects.php [NC]

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

redirect 301 /current-projects.php http://www.mysite.com/development.php

 

the non-www to www is commented out because that gives me the error

Link to comment
Share on other sites

Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com%{REQUEST_URI} [L,R=301]
# RewriteRule .* index.php/$0 [PT,L]
</IfModule>

 

This work on my computer (i modify my host to be www.mysite.com=127.0.0.1)

 

Options +FollowSymLinks

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
# RewriteRule ^(.*)$ http://www.mysite.com%{REQUEST_URI} [L,R=301]
RewriteRule .* index.php/$0 [PT,L]
</IfModule>

 

This doesn't work. (500 internal error/too many redirects) I didn't read it i just assumed it work and put it after.

[Fri May 01 14:51:26 2009] [error] [client 127.0.0.1] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary.

 

 

Only this in a .htaccess crash here :

Options +FollowSymLinks
RewriteEngine On
RewriteRule .* index.php/$0 [PT,L]

 

I am assuming it has never work, the htaccess was getting a rule before it that was a match and stop parsing the .htaccess but i'm not sure.

 

The last rules in the .htaccess "redirect 301 /current-projects.php http://www.mysite.com/development.php" will never be executed if you rewrite everything to index.php

Link to comment
Share on other sites

Forget about my last post ;)

 

Options +FollowSymLinks

<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com%{REQUEST_URI} [L,R=301]

# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^google2d216fed8ww53492f.html [NC]
RewriteCond %{REQUEST_FILENAME} !^y_key_8b37d87ae82wwr07b3e.html [NC]
RewriteCond %{REQUEST_FILENAME} !^robots.txt [NC]
RewriteCond %{REQUEST_FILENAME} !^current-projects.php [NC]

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

Redirect 301 /current-projects.php http://www.mysite.com/development.php

</IfModule>

 

This work fine on my computer. I only remove some space, sometime i search too far and overcomplicated everything ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.