 |
|
10-21-2009, 09:56 AM
|
|
#1
|
 |
|
Soldier (Level 11)
Join Date: Jan 2009
Posts: 127
|
Clean Url
I have spent the last two days trying to find what rewrite rules to use in .htaccess to create clean url's using wampserver. My url currently is
Code:
http://localhost/test/index.php?id=home
I would like it to read
Code:
http://localhost/test/home
Other pages all display the same with the id changing as each page is displayed.
Nothing I try seems to work in wampserver.
|
|
Add to del.icio.us
Can you digg it?
|
|
|
10-22-2009, 12:42 AM
|
|
#2
|
 |
|
Mod of the Underlay
Join Date: Jun 2002
Location: At a desk, hooked up and ready to rock
Posts: 17,242
|
what do you have at the moment?
Something like the following in your .htaccess should work:
Code:
RewriteEngine On
RewriteRule ^/test/(.*)$ /test/index.php?id=$1 [QSA,L]
That will only apply to pages in the test folder though...
__________________
Personal Blog (and photos): HorusKol
Articles on Programming and Development (PHP/HTML/CSS, C/C++, more): RandomTweak
The great secret that no SEO agent wants you to hear: if you build your website using w3c accessibility guidelines and your content is written for people, you will do better for longer in search engines than any other method...
|
|
Add to del.icio.us
Can you digg it?
|
|
|
10-22-2009, 01:21 AM
|
|
#3
|
 |
|
Soldier (Level 11)
Join Date: Jan 2009
Posts: 127
|
Sorry, that doesn't do anything unless I omit the space between the $ and /
then i get an error
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
|
|
Add to del.icio.us
Can you digg it?
|
|
|
10-22-2009, 09:07 AM
|
|
#4
|
 |
|
Mister Admin to you
Join Date: Jul 2001
Posts: 30,730
|
Internal errors are on the server, look for the error_log to see the error, you may not beable to use a htaccess file. Try this
RewriteRule ^/test/(.*) index.php?id=$1 [L]
|
|
Add to del.icio.us
Can you digg it?
|
|
|
10-22-2009, 10:28 AM
|
|
#5
|
 |
|
Soldier (Level 11)
Join Date: Jan 2009
Posts: 127
|
This is what my error log says
Code:
[Thu Oct 22 09:04:54 2009] [error] [client xxx.x.x.x]PHP Notice: Undefined index: id in C:\\wamp\\www\\test\\index.php on line 22
[Thu Oct 22 09:21:50 2009] [error] [client xxx.xxx.x.xxx] client denied by server configuration: C:/wamp/www/HNAP1
[Thu Oct 22 09:21:53 2009] [error] [client xxx.xxx.x.xxx] client denied by server configuration: C:/wamp/www/TEADevInfo
[Thu Oct 22 09:21:56 2009] [error] [client xxx.xxx.x.xxx] client denied by server configuration: C:/wamp/www/
Line 22 of index.php is
PHP Code:
if (in_array($_GET['id'], $pass)) {
The code used to display pages is
PHP Code:
<div class="wrapper">
<!--main page content goes here -->
<?php
// Define our array of allowed $_GET values
$pass = array('home','services','media','testimonials','bio','contact');
// If the page is allowed, include it:
if (in_array($_GET['id'], $pass)) {
include ($_SERVER['DOCUMENT_ROOT'] . 'test/pages/' . $_GET['id'] . '.php');
}
// If there is no $_GET['id'] defined, then serve the homepage:
elseif (!isset($_GET['id'])) {
include ($_SERVER['DOCUMENT_ROOT'] . 'test/pages/home.php');
}
// If the page is not allowed, send them to an error page:
else {
// This send the 404 header
header("HTTP/1.0 404 Not Found");
// This includes the error page
include ($_SERVER['DOCUMENT_ROOT'] . 'test/inc/error.php');
}
?>
</div>
|
|
Add to del.icio.us
Can you digg it?
|
|
|
10-22-2009, 07:17 PM
|
|
#6
|
 |
|
Mister Admin to you
Join Date: Jul 2001
Posts: 30,730
|
because you haven't defined this variable
$_GET['id']
Try this
PHP Code:
if (in_array($_GET['id'], $pass) AND !empty($_GET['id'])) {
|
|
Add to del.icio.us
Can you digg it?
|
|
|
10-22-2009, 08:05 PM
|
|
#7
|
 |
|
Soldier (Level 11)
Join Date: Jan 2009
Posts: 127
|
This is still in the error log
Code:
[Thu Oct 22 18:53:46 2009] [error] [client xxx.x.x.x]PHP Notice: Undefined index: id in C:\\wamp\\www\\test\\index.php on line 22
Using this in .htaccess
Code:
RewriteEngine On
RewriteRule ^/test/(.*)$ /test/index.php?id=$1
PHP Code:
<?php
// Define our array of allowed $_GET values
$pass = array('home','services','media','testimonials','bio','contact');
// If the page is allowed, include it:
if (in_array($_GET['id'], $pass) AND !empty($_GET['id'])) {
include ($_SERVER['DOCUMENT_ROOT'] . 'test/pages/' . $_GET['id'] . '.php');
}
// If there is no $_GET['id'] defined, then serve the homepage:
elseif (!isset($_GET['id'])) {
include ($_SERVER['DOCUMENT_ROOT'] . 'test/pages/home.php');
}
// If the page is not allowed, send them to an error page:
else {
// This send the 404 header
header("HTTP/1.0 404 Not Found");
// This includes the error page
include ($_SERVER['DOCUMENT_ROOT'] . 'test/inc/error.php');
}
?>
|
|
Add to del.icio.us
Can you digg it?
|
|
|
10-25-2009, 09:44 PM
|
|
#8
|
 |
|
Mod of the Underlay
Join Date: Jun 2002
Location: At a desk, hooked up and ready to rock
Posts: 17,242
|
and the URL you are testing with?
__________________
Personal Blog (and photos): HorusKol
Articles on Programming and Development (PHP/HTML/CSS, C/C++, more): RandomTweak
The great secret that no SEO agent wants you to hear: if you build your website using w3c accessibility guidelines and your content is written for people, you will do better for longer in search engines than any other method...
|
|
Add to del.icio.us
Can you digg it?
|
|
|
KEEP TABS |
|
SPONSORS |
| |
|
| |
|
|
| |
|