Page 1 of 1

mod_rewrite.

Posted: Fri Dec 21, 2007 1:15 am
by claws
http://localhost/newsite/?page=index.html
http://localhost/newsite/?page=page1&var1=val1
http://localhost/newsite/?page=page2&va ... &var2=val2

i want to make it look as
http://localhost/newsite/index (without extension)
http://localhost/newsite/page1(without extension)

sorry. i know that i should edit .htaccess.
and do something with mod_rewrite.
but i didnt read about it.

Choose the Right Board

Posted: Fri Dec 21, 2007 1:21 am
by s.dot
Basically you'll just need a few rewrite rules in your .htaccess file

Code: Select all

RewriteEngine On
RewriteRule ^newsite/(.+)$ index.php?page=$1
Moved to installation and configuration.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:1. Select the correct board for your query. Take some time to read the guidelines in the sticky topic.

Posted: Fri Dec 21, 2007 1:22 am
by claws
and i hope from security point of view
is this safe. or can it be exploited in anyway. i dont know much about security related issues.

Posted: Fri Dec 21, 2007 1:25 am
by s.dot
As long as you verify the page=index.html part. Check that index.html is indeed a file, and one that you wish to serve. it might help to strip .. (two periods) from the $_GET['page']

Posted: Fri Dec 21, 2007 1:27 am
by claws
scottayy wrote: RewriteEngine On
RewriteRule ^newsite/(.+)$ index.php?page=$1
this is the error i am getting

Server error!

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster.
Error 500

Posted: Fri Dec 21, 2007 1:30 am
by Rovas
First check that the Apache server has the file mod_rewrite.dll (on Win systems) which does the url rewriting.
Second edit the htaccess file starting the rewrite module, put the rules using regular expressions and that' s that for the Apache.
For php to recognize the parameters passed use a global variable

Code: Select all

$_SERVER['PHP_SELF']
to get the parameters then you use them.
Some tutorials first, second, third.

Posted: Sat Dec 22, 2007 12:38 am
by claws
thanks.

mod_rewrite.so is present in modules directory.
and in httpd.conf
#LoadModule mod_rewrite.conf

was commented intially. i have uncommented in and restarted the server.
now its not showing the 500 error.
but showing 404 error

http://localhost/newsite/page1 --- accessed url(it simply showing 404 error)

is my .htaccess file in both root directory aswell as in 'newsite' directory
RewriteEngine On
RewriteRule ^newsite/(.+)$ index.php?page=$1
[/quote]