Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Need help with URL rewriting |
|
Author |
|
Anturis
Joined: 20 Apr 2011 Posts: 7 Location: Turkey
|
Posted: Fri 07 Oct '11 10:48 Post subject: Need help with URL rewriting |
|
|
Hi,
I have been reading about URL rewriting and mod_rewrite for a while but it seems I cannot make it work as I want. Here is my website I am working on:
On this site I have different type of pages such as page.php, tutorial.php, post.php and category.php. Here is how the URLs are at the moment:
Code: | configureweb.com/page.php?page=about
configureweb.com/tutorial.php?tutorial=html-tutorial
configureweb.com/post.php?post=sample-post
configureweb.com/category.php?category=hosting-and-domains |
and here is how I want them to be:
Code: | configureweb.com/page/about
configureweb.com/tutorial/html-tutorial
configureweb.com/post/sample-post
configureweb.com/category/hosting-and-domains |
I tried something like the following code for pages:
Code: | RewriteRule ^page/([A-Za-z0-9-]+)/?$ page.php?page=$1 [L] |
Code: | <a href="page/about">About</a> |
It redirects to the correct page but the stylesheet is not active and links on that page become like this:
Code: | configureweb.com/page/page/about/ |
What am I doing wrong? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Fri 07 Oct '11 12:53 Post subject: |
|
|
You can have that easier. OK mod_rewrite works, but not easy to set up.
Use PATH_INFO instead. page,tutorial,post and category need to be a php file without the .php file extension
Code: |
<Files page>
SetHandler application/x-httpd-php
</Files>
<Files tutorial>
SetHandler application/x-httpd-php
</Files>
<Files post>
SetHandler application/x-httpd-php
</Files>
<Files category>
SetHandler application/x-httpd-php
</Files>
|
Than side of that php files
Code: |
<?php
$args = split('/', $_SERVER['PATH_INFO'];
switch( $args[1] ) {
case 'foo' :
// stuff here
break;
case 'bar' :
// stuff here
break;
default :
// Other stuff
break;
}
?>
|
If you still have a question please ask again. |
|
Back to top |
|
|
|
|
|
|