i need some help from the experts.
I have some rewrite rules:
post.php go to http://example.com/post/3/
RewriteRule ^post/([A-Za-z0-9-]+)/?$ post.php?id=$1 [NC,L]
It Works!
But, How can i add a new rewrite rule to the NEW Page Users.php after post/ID/
And get the ID in Users.php (Users.php?id=3)
Like this http://example.com/post/3/users
Thanks!
If you want
/post/3/users/to go to/Users.php?id=3, you have to put that rule before your existing rule. Your existing rule matches/post/3/'which is a prefix of what this additional rule matches, so that rule will never fire if it is after.Another thing: you tagged your post with
.htaccess. Does that mean your rewrites are in a.htaccess? If so, you should useRewriteBasebecause your rewrites are relative. Why it’s working is probably that you are allowing a 1:1 correspondence between paths and URLs on your webserver.In a per-directory context like
.htaccess, mod_rewrite is working with path names, not URLs. But if you do a relative rewrite, the path is turned into a URL and fed back into the Apache’s request handling chain to be processed over again. How the path is turned into a URL is that the contents ofRewriteBaseare added to the front. If you don’t haveRewriteBasethen a silly thing happens: the path to your directory (that was removed for theRewriteRuleis just tacked back on!).Example: suppose your DocumentRoot is
/var/www. Suppose the browser asks for the URL/foo. This gets translated to the path/var/www/fooIf inside the.htaccessfor/var/www/you rewritefootobar(andRewriteBaseis not set), then mod_rewrite will generate the URL/var/www/bar: it just takes the/var/www/directory that was stripped off and puts it back on. Now that can be made to work: just make/var/www/a valid URL going to that directory. For instance withBut that is hacky. The right way is to have
RewriteBase /in the .htaccess. So whenfoois rewritten tobar, it just gets a/in front and becomes the url/bar. This is fed back to the server and will resolve back to the document root again “naturally”.I used hacks like that before I understood the rewriting. I even used
/as aDocumentRoot! That made everything work out since then most URLs are paths: you don’t have to think of URLs a an abstraction separate from your filesystem paths. But it’s a dangerous, silly thing.