Page 1 of 1
[SOLVED] - 301 Redirect Root URL
Posted: Wed Nov 11, 2009 4:05 am
by richbothe
CMSMS Ver. 1.6.6
Whenever I enable this rewrite rule in my .htaccess file the redirect works, but then forms on my site don't work.
Code: Select all
#RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
#RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
Is there a better way to force it so that
http://domain.com redirects to
http://www.domain.com? I know enough about .htaccess files to write one with the help of a tutorial, but not much more.
Here a sample of my complete .htaccess file. Any help/suggestions to make this better is much appreciated.
Code: Select all
#php_flag magic_quotes_gpc Off
#php_flag register_globals Off
#php_flag session.use_trans_sid Off
#php_value upload_max_filesize 16M
#php_value memory_limit 16M
# Make sure you have Options FollowSymLinks
# and Allow on
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
#Rewrites page.shtml as index.php?page
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
# 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 [QSA]
#AuthType Basic
#AuthName "Password Required"
#AuthUserFile /aomam.org/httpdocs/auth/.passwd
#AuthGroupFile /aomam.org/httpdocs/auth/group.file
#require valid-user
#Require Group admins
#RewriteEngine on
#RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
#RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
Rich
Re: 301 Redirect Root URL
Posted: Wed Nov 11, 2009 3:20 pm
by Sonya
Forms often do not work because of the trailing slash condition:
Code: Select all
# 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]
Re: 301 Redirect Root URL
Posted: Wed Nov 11, 2009 3:34 pm
by richbothe
Turning off the trailing slash condition seems to make no difference as the forms still don't work.
Code: Select all
# 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]
Re: 301 Redirect Root URL
Posted: Wed Nov 11, 2009 3:58 pm
by Sonya
For my sites I always use:
Code: Select all
# Redirect to canonical domain name with www
RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [NC]
RewriteRule ^(.*) http://www.yourdomain.com/$1 [L,R=301]
The only difference in your version is different usage of the end delimiter $ and missing escape in the first line:
Code: Select all
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
Try this, it sure works with every form I have ever tested.
Re: 301 Redirect Root URL
Posted: Wed Nov 11, 2009 4:51 pm
by Rolf
Whenever I enable this rewrite rule in my .htaccess file the redirect works, but then forms on my site don't work.
This is a known bug, add this into your htaccess.
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]
Regards, Rolf
Re: 301 Redirect Root URL
Posted: Wed Nov 11, 2009 6:07 pm
by richbothe
Hmm... Still not working. And because my forms don't work this also prevents me from logging into CMS Admin. Here is my revised .htaccess file.
Code: Select all
# Make sure you have Options FollowSymLinks
# and Allow on
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
#Rewrites page.shtml as index.php?page
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
# 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]
# 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 [QSA]
RewriteCond %{HTTP_HOST} ^theplaygroundent\.com$ [NC]
RewriteRule ^(.*)$ http://www.theplaygroundent.com/$1 [L,R=301]
Re: 301 Redirect Root URL
Posted: Wed Nov 11, 2009 6:30 pm
by Sonya
richbothe wrote:
Hmm... Still not working. And because my forms don't work this also prevents me from logging into CMS Admin. Here is my revised .htaccess file.
Rename your .htaccess file and try to login in admin without. If it does not work, then you do not have any problem with forms but with your installation in general.
Explain exactly: "forms do not work". Do you get an error?
Re: 301 Redirect Root URL
Posted: Wed Nov 11, 2009 6:35 pm
by richbothe
Renaming .htaccess allows me to login to admin, but then causes a 404 error for all my pages except for my home page. I have "mod_write" enabled for pretty urls.
Re: 301 Redirect Root URL
Posted: Wed Nov 11, 2009 6:38 pm
by JeremyBASS
richbothe wrote:
Hmm... Still not working. And because my forms don't work this also prevents me from logging into CMS Admin. Here is my revised .htaccess file.
Code: Select all
# Make sure you have Options FollowSymLinks
# and Allow on
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
#Rewrites page.shtml as index.php?page
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
# 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]
# 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 [QSA]
RewriteCond %{HTTP_HOST} ^theplaygroundent\.com$ [NC]
RewriteRule ^(.*)$ http://www.theplaygroundent.com/$1 [L,R=301]
try this too..
Code: Select all
# BEGIN Optional settings
# Turns off directory browsing
# not absolutely essential, but keeps people from snooping around without
# needing empty index.html files everywhere
Options -Indexes
# Deny access to config.php
# This can be useful if php ever breaks or dies
# Use with caution, this may break other functions of CMSms that use a config.php
# file. This may also break other programs you have running under your CMSms
# install that use config.php. You may need to add another .htaccess file to those
# directories to specifically allow config.php.
<Files "config.php">
order allow,deny
deny from all
</Files>
# Sets your 403 error document
# not absolutely essential to have,
# or you may already have error pages defined elsewhere
ErrorDocument 403 /forbidden403.shtml
# No sense advertising what we are running
ServerSignature Off
# END Optional Settings
# BEGIN CMSMS and Rewrite Rules
# Make sure you have Options FollowSymLinks
# and Allow on
RewriteEngine On
# Might be needed in a subdirectory
#RewriteBase /
# URL Filtering helps stop some hack attempts
#IF the URI contains a "http:"
RewriteCond %{QUERY_STRING} http\: [OR]
#OR if the URI contains a "["
RewriteCond %{QUERY_STRING} \[ [OR]
#OR if the URI contains a "]"
RewriteCond %{QUERY_STRING} \] [OR]
#OR if the URI contains a "<__script__>"
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
#OR script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
#OR any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) [OR]
#IF the URI contains UNION
RewriteCond %{QUERY_STRING} UNION [OR]
#OR if the URI contains a *
RewriteCond %{QUERY_STRING} \*
#then deny the request (403)
RewriteRule ^.*$ - [F,L]
# End URL Filtering
# force CMSMS www IN URL
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# END CMSMS force www IN URL
# CMSMS Rewriting
# Set assume mod_rewrite to true in config.php and clear CMSMS cache
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
This has worked on 99% of all servers I've placed it on... Hope that helps as you were forcing the www after the pretty url and doing the pretty url twice..
Cheers
Jeremy
Re: 301 Redirect Root URL
Posted: Wed Nov 11, 2009 6:48 pm
by richbothe
I changed .htaccess to the code you provided Jeremy (thanks), and that solved the 404 error, but still forms not working and can't login to admin.
The website is
http://theplaygroundent.com and the admin is
http://theplaygroundent.com/eadmincp.
I setup a demo user login that you can use to see what's happening.
UN: demouser
PW: password
Re: 301 Redirect Root URL
Posted: Wed Nov 11, 2009 6:54 pm
by JeremyBASS
first.. version? if all up to date .. then... as a test of to the login.php (ie: admin/themes/NCleanGrey/login.php) and change the
to
but..
also insure your config file is right...
#Name of the admin directory
$config['admin_dir'] = 'eadmincp';
since your useing that eadmincp.
Re: 301 Redirect Root URL
Posted: Wed Nov 11, 2009 7:02 pm
by JeremyBASS
in fact I just tested that.. and that change logs you in...
Re: 301 Redirect Root URL
Posted: Wed Nov 11, 2009 7:11 pm
by Sonya
Well, simple solution:
Open the file config.php and change
Code: Select all
$config['root_url'] = 'http://theplaygroundent.com';
to
Code: Select all
$config['root_url'] = 'http://www.theplaygroundent.com';
That is

Re: 301 Redirect Root URL
Posted: Wed Nov 11, 2009 7:19 pm
by richbothe
I made the change to the config file and that did it! Works like a charm now. Thank you both for your help. I've been having this issue on other sites for a little while and just never felt like dealing with it. Cheers!