Page 1 of 1

Address rewrite question

Posted: Thu Sep 08, 2005 5:23 pm
by jd
Hi,

I have the following question which came to me today. How can I make the CMSMS make the address like:

instead of http://domain.com/?page=something
to be http://domain.com/something

Please help.

Re: Address rewrite question

Posted: Thu Sep 08, 2005 6:17 pm
by raednesh
download the config.php from the your site root directory.

Change the following line:

$config['assume_mod_rewrite'] = false;

to

$config['assume_mod_rewrite'] = true;

This will make CMSMS use http://domain.com/something.shtml instead of http://domain.com/?page=something

Good luck

Re: Address rewrite question

Posted: Thu Sep 08, 2005 6:20 pm
by jd
super! 10x!

but how can I make it without the .shtml at the end?

Re: Address rewrite question

Posted: Thu Sep 08, 2005 6:41 pm
by raednesh
this is a little tricker, there are two steps involved:
1- Make CMSMS output the links without the .shtml extension.
2- Configure the server to forward the new formart to the correct page.

The first part is easy: open the config.php file and change:

$config['page_extension'] = '.shtml';

to

$config['page_extension'] = '';

The first part is over, now the second part:

1- On the root directory you will find a file named .htaccess (if you don't find it, you are suppose to upload it from the doc directory of the source package of CMSMS, or you can create an empty text file named .htaccess).
2- Download that file and open it, it should be like this:

php_flag magic_quotes_gpc Off
php_flag register_globals Off
php_flag session.use_trans_sid Off

# Make sure you have Options FollowSymLinks
# and Allow on
RewriteEngine On

#Rewrites page.shtml as index.php?page
RewriteRule ^(.+)\.shtml$ index.php?page=$1 [QSA]

Change the following line:

RewriteRule ^(.+)\.shtml$ index.php?page=$1 [QSA]

to

RewriteRule ^(.+) index.php?page=$1 [QSA]

And you are all set, upload and enjoy search engine friendly urls :)

Re: Address rewrite question

Posted: Thu Sep 08, 2005 6:59 pm
by jd
10x raednesh!
You are of great help!

However, it didn't quite worked our from the first time (and still doesn't work). I've done all as to what you said, but I get a Error 404: File not found.

Do you where might the problem be?

Re: Address rewrite question

Posted: Thu Sep 08, 2005 7:02 pm
by raednesh
you get File not found error normally if there is something wrong with the rewrite rule. The one I wrote above will transfer a request like:

http://domain.com/something

to

http://domain.com/index.php?page=something.

Is this how your system setup or is CMSMS is under a sub-directory? If that's not the case, do you have a url I can check out?

Re: Address rewrite question

Posted: Thu Sep 08, 2005 7:04 pm
by jd
it is under the root/cms

like domain.com/cms

does this matter?

Re: Address rewrite question

Posted: Thu Sep 08, 2005 7:05 pm
by raednesh
yes because in that case the rewrite rule should be:

RewriteRule ^(.+) cms/index.php?page=$1 [QSA]

instead of

RewriteRule ^(.+) index.php?page=$1 [QSA]

Try it and let me know.

Re: Address rewrite question

Posted: Thu Sep 08, 2005 7:14 pm
by jd
nope. it didn't worked. I think that I've made a mistake somewhere in step 1 (though that I've made everything as told).
because when I remove the .htaccess (so rewrite rules are applied), and in the config.php leave the .shtml extension just to test
when I try domain.com/cms/new.shtml --> still shows me an Error 404

is there something else to be edited in the config.php besides the $config['assume_mod_rewrite'] = true;

Re: Address rewrite question

Posted: Thu Sep 08, 2005 7:20 pm
by raednesh
from your test site I can see that the CMSMS is using the .shtml, now you still need the .htaccess file to tell the server to redirect the .shtml requests to the correct page, so your .htaccess should look like:

php_flag magic_quotes_gpc Off
php_flag register_globals Off
php_flag session.use_trans_sid Off

# Make sure you have Options FollowSymLinks
# and Allow on
RewriteEngine On

#Rewrites page.shtml as index.php?page
RewriteRule ^(.+)\.shtml$ index.php?page=$1 [QSA]


If that didn't work, change the last line to:

RewriteRule ^(.+)\.shtml$ cms/index.php?page=$1 [QSA]

Keep us updated how it goes :)

Re: Address rewrite question

Posted: Thu Sep 08, 2005 7:48 pm
by jd
Well, 10x to raednesh, we've worked out the solution to my problem is the following:

The .htaccess file should look like this:

php_flag magic_quotes_gpc Off
php_flag register_globals Off
php_flag session.use_trans_sid Off

# Make sure you have Options FollowSymLinks
# and Allow on
RewriteEngine On

rewritecond %{REQUEST_FILENAME} !^(.+)\admin

#Rewrites page.shtml as index.php?page
RewriteRule ^(.+) /cms/index.php?page=$1 [QSA]