removing index.php AND removing www from url
Posted: 16 May 2008 12:07 PM   [ Ignore ]  
Grad Student
Avatar
Rank
Total Posts:  77
Joined  03-15-2008

First let me say that I understand removing index.php from the URL is not supported.

I followed the instructions here using the Include method described.

If I use this:

Options +FollowSymlinks
RewriteEngine on
RewriteCond
$1 !^(images|mqgyplMhrp8|themes|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule
^(.*)$ /index.php/$1 [L]
RewriteCond
%{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule
^(.*)$ http://domain.com/$1 [R=301,L]

... and enter http://domain.com in the browser, it correctly hides index.php. However, if I enter http://www.domain.com in the browser, it correctly strips the www but does not hide index.php (it shows up as http://domain.com/index.php)

I’m trying to figure out how to get both rules to work together, I would appreciate any advice. (I did try removing ,L from the last line, doesn’t change anything.) When I reverse the instructions like this, I actually get a server error.

Options +FollowSymlinks
RewriteEngine on
RewriteCond
%{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule
^(.*)$ http://domain.com/$1 [R=301,L]
RewriteCond $1 !^(images|mqgyplMhrp8|themes|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule
^(.*)$ /index.php/$1 [L]

Thanks, Paul

Profile
 
 
Posted: 16 May 2008 01:34 PM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  14059
Joined  05-15-2004

You can’t use [L] (as in Last rule) more than once. Well, you can, but then mod_rewrite will not perform any further rewrites, which is what you’re seeing.

 Signature 

Everything will be good in the end. If it’s not good, it’s not the end.

Profile
MSG
 
 
Posted: 16 May 2008 03:02 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Avatar
Rank
Total Posts:  77
Joined  03-15-2008

I just tried this:

Options +FollowSymlinks
RewriteEngine on
RewriteCond
$1 !^(images|mqgyplMhrp8|themes|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule
^(.*)$ /index.php/$1
RewriteCond
%{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule
^(.*)$ http://domain.com$1 [R=301]


And I get the same result:
http://www.domain.com yields http://domain.com/index.php
http://domain.com yields http://domain.com

Profile
 
 
Posted: 16 May 2008 03:06 PM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  14059
Joined  05-15-2004

No guarantees, but try reversing them, like you had before:

RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule
^(.*)$ http://domain.com/$1 [R=301]
RewriteCond $1 !^(images|mqgyplMhrp8|themes|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule
^(.*)$ /index.php/$1 [L]

 Signature 

Everything will be good in the end. If it’s not good, it’s not the end.

Profile
MSG
 
 
Posted: 16 May 2008 04:32 PM   [ Ignore ]   [ # 4 ]  
Grad Student
Avatar
Rank
Total Posts:  77
Joined  03-15-2008

Doing that actually creates an error:

Moved Permanently

The document has moved here.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

Profile
 
 
Posted: 16 May 2008 05:33 PM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1251
Joined  01-07-2008

You actually want to keep that L in there.  Also try using RewriteBase and relative urls.

<IfModule mod_rewrite.c>
# Turn Rewrite Engine on
RewriteEngine On

# Set our base so we have nice relative paths
RewriteBase /

# Check for www and remove - skip otherwise
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule
^(.*)$ http://%1/$1 [R=301,L]

# Remove index.php - we only get here if the above rule passes
RewriteCond $1 !^(images|mqgyplMhrp8|themes|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule
^(.*)$ index.php/$1 [L]
</IfModule>

 Signature 

Blog | Twitter | Coffee

Profile
 
 
Posted: 16 May 2008 07:48 PM   [ Ignore ]   [ # 6 ]  
Grad Student
Avatar
Rank
Total Posts:  77
Joined  03-15-2008

beautiful

thank you!

Profile
 
 
Posted: 16 May 2008 10:56 PM   [ Ignore ]   [ # 7 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  14059
Joined  05-15-2004

Thanks for sharing, inparo. Yes, mod_rewrite can be a tricky beast at the best of times ...

 Signature 

Everything will be good in the end. If it’s not good, it’s not the end.

Profile
MSG
 
 
Posted: 08 June 2008 04:45 PM   [ Ignore ]   [ # 8 ]  
Lab Assistant
RankRank
Total Posts:  116
Joined  06-02-2005

Hi,  how would you rewrite this to turn mysite.com into www.mysite.com?  Thanks

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 10:33 AM
Total Registered Members: 62686 Total Logged-in Users: 45
Total Topics: 77249 Total Anonymous Users: 35
Total Replies: 417001 Total Guests: 266
Total Posts: 494250    
Members ( View Memberlist )