mod_rewrite.

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
claws
Forum Commoner
Posts: 73
Joined: Tue Jun 19, 2007 10:54 am

mod_rewrite.

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Choose the Right Board

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
claws
Forum Commoner
Posts: 73
Joined: Tue Jun 19, 2007 10:54 am

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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']
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
claws
Forum Commoner
Posts: 73
Joined: Tue Jun 19, 2007 10:54 am

Post 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
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Post 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.
claws
Forum Commoner
Posts: 73
Joined: Tue Jun 19, 2007 10:54 am

Post 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]
Post Reply