2

I apologize if this has been asked numerous times, all of the reading I've done I can't seem to figure this out.

I'm building a site where the index page loads a template based on the url "index.php?p=pagename". This is working fine, however in some instances I need to pass an id as well "index.php?p=pagename&id=#". Ideally I would like it to look like... /pagename/id or /pagename/id/...

here's what my hatccess file looks like.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /manage/
RewriteRule ^([A-Za-z0-9-]+)/?$ ?p=$1 [NC]
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/?$ index.php?p=$1&id=$2
</IfModule>

Any help would be much appreciated.

MAtkins
  • 53
  • 6
  • possible duplicate of [URL rewriting with PHP](http://stackoverflow.com/questions/16388959/url-rewriting-with-php) – Frank van Wijk May 05 '15 at 16:26
  • Also check if your server has mod rewrite enabled – Germanaz0 May 05 '15 at 16:44
  • Thanks, sorry for the duplication, I guess there's never an explanation of.. if you set it up to handle two parameters, it also works with only one parameter. That's where my confusion may have been happening. – MAtkins May 05 '15 at 17:13
  • mod rewrite is enabled. As I mentioned, the first rewrite rule is working perfectly. As I'm building the site, I've come across a need to occasionally pass an id for $_GET.... and it just isn't happening. Unfortunately I have very little understanding of hatches.... – MAtkins May 05 '15 at 17:28
  • *htaccess... spell check changed it to 'hatches' – MAtkins May 05 '15 at 17:36

1 Answers1

2

Try this :

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /manage/
RewriteRule ^([a-zA-Z0-9-]+)/?$ /manage/index.php?p=$1 [QSA,NC,L]
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ /manage/index.php?p=$1&id=$2 [QSA,NC,L]
</IfModule>
Amit Verma
  • 40,709
  • 21
  • 93
  • 115