[SOLVED] Removing www by using .htaccess causes problems

Help with getting the CMS CORE package up and running. This does not include 3rd party modules, PHP scripts, anything downloaded via module manager or from any external source.
User avatar
opawaldburger
Forum Members
Forum Members
Posts: 94
Joined: Tue Nov 04, 2008 2:10 pm

[SOLVED] Removing www by using .htaccess causes problems

Post 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
Last edited by opawaldburger on Tue Mar 16, 2010 4:23 pm, edited 1 time in total.
- Sir, we are sourrounded!
- Excellent, now we can attack in any direction!
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Removing www by using .htaccess causes problems

Post 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...
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: Removing www by using .htaccess causes problems

Post by Rolf »

opawaldburger wrote: Every input is welcome ;)
greez, opa
Perhaps: http://forum.cmsmadesimple.org/index.ph ... 912.0.html

®
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
opawaldburger
Forum Members
Forum Members
Posts: 94
Joined: Tue Nov 04, 2008 2:10 pm

Re: Removing www by using .htaccess causes problems

Post by opawaldburger »

@Dr. CSS: Now I did, but unfortunately nothing happened :(
@Rolf: I tried it this way, too, but same problems! Thanks, though!
- Sir, we are sourrounded!
- Excellent, now we can attack in any direction!
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: Removing www by using .htaccess causes problems

Post 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
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
opawaldburger
Forum Members
Forum Members
Posts: 94
Joined: Tue Nov 04, 2008 2:10 pm

Re: Removing www by using .htaccess causes problems

Post 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
- Sir, we are sourrounded!
- Excellent, now we can attack in any direction!
owr_bgld

Re: Removing www by using .htaccess causes problems

Post 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"
Last edited by owr_bgld on Tue Mar 16, 2010 11:14 am, edited 1 time in total.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: Removing www by using .htaccess causes problems

Post 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  :)
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
opawaldburger
Forum Members
Forum Members
Posts: 94
Joined: Tue Nov 04, 2008 2:10 pm

Re: Removing www by using .htaccess causes problems

Post 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
Last edited by opawaldburger on Mon Mar 15, 2010 7:22 pm, edited 1 time in total.
- Sir, we are sourrounded!
- Excellent, now we can attack in any direction!
owr_bgld

Re: Removing www by using .htaccess causes problems

Post 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.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: Removing www by using .htaccess causes problems

Post 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  :)
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
opawaldburger
Forum Members
Forum Members
Posts: 94
Joined: Tue Nov 04, 2008 2:10 pm

Re: Removing www by using .htaccess causes problems

Post 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
- Sir, we are sourrounded!
- Excellent, now we can attack in any direction!
owr_bgld

Re: Removing www by using .htaccess causes problems

Post 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
Last edited by owr_bgld on Mon Mar 15, 2010 7:46 pm, edited 1 time in total.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: Removing www by using .htaccess causes problems

Post 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  :)
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
opawaldburger
Forum Members
Forum Members
Posts: 94
Joined: Tue Nov 04, 2008 2:10 pm

Re: Removing www by using .htaccess causes problems

Post 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
- Sir, we are sourrounded!
- Excellent, now we can attack in any direction!
Locked

Return to “[locked] Installation, Setup and Upgrade”