Help with mod_rewrite

Discuss practical ways rearrange URLs using mod_rewrite.

Help with mod_rewrite

Postby sethadam1 » Tue Sep 16, 2008 5:30 am

I am trying to fix an old static html structure like this:

/faq/page.html
/faq/page2.html
/faq/whatever55.html

I would like to make it dynamic. This is what I have so far, but it's not working:

Code: Select all
RewriteEngine Off
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /path/to/faq/
RewriteCond %{REQUEST_URI} !^faq.php$
RewriteRule   ^[-a-zA-z0-9.]+$ faq.php?p=$1 [NC,L]
</IfModule>


The idea is what I can eventually get something like faq.php?p=page.html. But it's not working. In fact, when I echo out the contents of the "p" variable on faq.php, it's got faq.php in it, almost like a loop. Can anyone give me a hand?

Thanks in advance
sethadam1
 
Posts: 1
Joined: Tue Sep 16, 2008 5:27 am

Postby richardk » Tue Sep 16, 2008 11:54 am

It is a loop. REQUEST_URI is everything after the domain and before any query string.

Where is faq.php? /faq/faq.php?

Try the following in a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks -MultiViews

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{REQUEST_URI} !^/faq/faq\.php$ [NC]
  RewriteRule ^faq/[-a-z0-9]+\.html$ /faq/faq.php?p=$1 [NC,L]
</IfModule>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 28 guests

cron