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.

5
  • possible duplicate of URL rewriting with PHP Commented May 5, 2015 at 16:26
  • Also check if your server has mod rewrite enabled Commented May 5, 2015 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. Commented May 5, 2015 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.... Commented May 5, 2015 at 17:28
  • *htaccess... spell check changed it to 'hatches' Commented May 5, 2015 at 17:36

1 Answer 1

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> 
Sign up to request clarification or add additional context in comments.

8 Comments

This isn't working. do I maybe need to change how I'm writing the href for page links?
In which folder is the index.php file?
You also need to add a base tag to the head of your document so that pages can can use css and other relative links
There is a config file that defines the base url as well as the base directory included in the index page
Sorry if I'm misunderstanding something, this still isn't working. My page links look like: '<a href=/manage/pagename>' which works with my first rewrite rule from my post, it also works without '/manage/', but doesn't work with the rule you've posted.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.