Page 1 of 2

[SOLVED] Removing www by using .htaccess causes problems

Posted: Mon Mar 15, 2010 6:05 pm
by opawaldburger
Hi People!

Today I wanted to modify my .htaccess file to "redirect" every URL request from www.example.com/site/ to http://example.com/site/.

I used this code:

Code: Select all

#Rewrites www URLS to non-www URLS
RewriteCond %{HTTP_HOST} ^www.benjamin-karl.com$ [NC]
RewriteRule ^(.*)$ http://benjamin-karl.com/$1 [R=301,L]
Unfortunately there are two problems: The guestbook doesn't work any more (nothing happens when clicking on the button to add a new entry) and I can't access the admin area, because of some reason it requires the www (yes, I could solve it by adding a specific .htaccess file in the admin folder, but itsn't there a more convenient way?)

This is my file right now:

Code: Select all

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1&gdir=$0 [QSA]
As some will have noticed, I'm using pretty URLs, maybe that's also reason why it doesn't work.

Every input is welcome ;)
greez, opa

Re: Removing www by using .htaccess causes problems

Posted: Mon Mar 15, 2010 6:16 pm
by Dr.CSS
Have you changed your config.php to reflect that the site now is seen as http;;//site.com and not www  .site

NOTE: the ;; and etc. is so they don't become links...

Re: Removing www by using .htaccess causes problems

Posted: Mon Mar 15, 2010 6:18 pm
by Rolf
opawaldburger wrote: Every input is welcome ;)
greez, opa
Perhaps: http://forum.cmsmadesimple.org/index.ph ... 912.0.html

®

Re: Removing www by using .htaccess causes problems

Posted: Mon Mar 15, 2010 6:31 pm
by opawaldburger
@Dr. CSS: Now I did, but unfortunately nothing happened :(
@Rolf: I tried it this way, too, but same problems! Thanks, though!

Re: Removing www by using .htaccess causes problems

Posted: Mon Mar 15, 2010 6:41 pm
by Rolf
Ohh wait  ::)

Try adding these lines in the .htaccess file:

Code: Select all

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
# except for form POSTS                                        <-----------------
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_METHOD} !POST$            <-----------------
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
Rolf

Re: Removing www by using .htaccess causes problems

Posted: Mon Mar 15, 2010 6:58 pm
by opawaldburger
sry, stays the same. the problem is, that the guestbook requires the "www"
don't ask me why, but obviously that's the problem. for the next 15 minutes I going to have the modified .htaccess uploaded, so when visiting the following site, you can what I mean!
http://benjamin-karl.com/gaestebuch

that's what the file looks now:

Code: Select all

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1&gdir=$0 [QSA]

#Rewrites www URLS to non-www URLS
RewriteCond %{HTTP_HOST} ^www.benjamin-karl.com$ [NC]
RewriteRule ^(.*)$ http://benjamin-karl.com/$1 [R=301,L]
greez, opa

Re: Removing www by using .htaccess causes problems

Posted: Mon Mar 15, 2010 7:09 pm
by owr_bgld
your form:

logisch dass net funzt ;)

only one (or a few) change(s) in the template(s) schould solve the problem - only look where in the guestbook templates you have www.

EDIT: Sorry, I had to correct my "austrian english"

Re: Removing www by using .htaccess causes problems

Posted: Mon Mar 15, 2010 7:11 pm
by Rolf
The fix I posted is for problems with the POST function in combination with a trailing slash in the url, which you have...
Your newsletter form isn't working too  ;) Same problem.

Perhaps:
RewriteRule ^(.+)$ index.php?page=$1&gdir=$0 [QSA]
The default line is
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

Rolf  :)

Re: Removing www by using .htaccess causes problems

Posted: Mon Mar 15, 2010 7:20 pm
by opawaldburger
@owr_bgld: wie woa, wie woa.;) there's just the problem, that I already WANTED changed the URL in the Guestbook-Templates, but there's nothing to change :S

@rolf: changed it to this version:

Code: Select all

RewriteRule ^(.+)$ index.php?page=$1 [QSA]
go visit the site to see what's happening now - not much better, though

greez

Re: Removing www by using .htaccess causes problems

Posted: Mon Mar 15, 2010 7:23 pm
by owr_bgld
aho - sorry that was not really clear thinking - or how do you say in english "shit happens?" I don't work really much with forms (it's a time ago)


You can't change the forms thats right - but did you try changing the config.php - path setting. Make the root url without the www.

Re: Removing www by using .htaccess causes problems

Posted: Mon Mar 15, 2010 7:27 pm
by Rolf
Dr.CSS wrote: Have you changed your config.php to reflect that the site now is seen as http;;//site.com and not www  .site

NOTE: the ;; and etc. is so they don't become links...

Code: Select all

<base href="http://www.benjamin-karl.com/" />
Tried this yet?:

Code: Select all

#Document root as seen from the webserver.  No slash at the end
#If page is requested with https use https as root url
#e.g. http://blah.com
$config['root_url'] = 'http://benjamin-karl.com';
No www. and no slash at the end.

Rolf  :)

Re: Removing www by using .htaccess causes problems

Posted: Mon Mar 15, 2010 7:35 pm
by opawaldburger
@owr_bgld: Yeah, tried that. But NOTHING happened. I don't know which effects it should take, but the ones I could imagine didn't happen.

@Rolf: I already did that - but as you can see even the base_url doesn't change. already typed it manually and removed the {metadata}-tag - no result!

@all: I am wondering if I'm the only one to rewrite URLs and using the guestbook. Is there anyone who uses the same and could help anyhow - even if you say it works for your site...!?

Thanks to all you three who helped so far!!!

greez, opawaldburger

Re: Removing www by using .htaccess causes problems

Posted: Mon Mar 15, 2010 7:44 pm
by owr_bgld
ok wait - mir foit grod wos ei

I had an maybe similar problem - my pretty urls didn't work. For me there was to much code in the .htaccess.

I only need this lines (and this at 4 different servers with four different pages):

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

I think now you have only to make the changes like Rolf suggested


EDIT: Don't forget to change the root_path in the config without www. again - and sorry, i had to "revise" my english two times

Re: Removing www by using .htaccess causes problems

Posted: Mon Mar 15, 2010 7:52 pm
by Rolf
opawaldburger wrote: @all: I am wondering if I'm the only one to rewrite URLs and using the guestbook. Is there anyone who uses the same and could help anyhow - even if you say it works for your site...!?
Check http://atmytestsite.com/guestbook.html

Rolf  :)

Re: Removing www by using .htaccess causes problems

Posted: Mon Mar 15, 2010 8:02 pm
by opawaldburger
@owr_bgld: no problem. still, this code won't remove the www trom the URL. This only makes sure that the pretty URLs work ;)
@Rolf: Perfect! That's exactly how it should work! What did you do or not do?

Opa