daveoffy Posted March 1, 2009 Share Posted March 1, 2009 Can I have 2 rewrite rules for a single URL. I want a url like this http://site.com/edit.php?file=10?site=1 or whatever. I need a file and site in the URL. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/147388-solved-htaccess-2x-rewriterules-in-a-single-url/ Share on other sites More sharing options...
corbin Posted March 1, 2009 Share Posted March 1, 2009 Yes. Quote Link to comment https://forums.phpfreaks.com/topic/147388-solved-htaccess-2x-rewriterules-in-a-single-url/#findComment-773641 Share on other sites More sharing options...
daveoffy Posted March 1, 2009 Author Share Posted March 1, 2009 Could I have some code example? This is what I have so far Options +FollowSymlinks RewriteEngine on RewriteRule /fileid/([0-9])$ editor.php?fileid=$1 Quote Link to comment https://forums.phpfreaks.com/topic/147388-solved-htaccess-2x-rewriterules-in-a-single-url/#findComment-773730 Share on other sites More sharing options...
wildteen88 Posted March 1, 2009 Share Posted March 1, 2009 Just expand your rewrite rule further # matches: /fileid/X/site/Y RewriteRule /fileid/([0-9]+)/site/([0-9]+)$ editor.php?fileid=$1&site=$2 [L] Quote Link to comment https://forums.phpfreaks.com/topic/147388-solved-htaccess-2x-rewriterules-in-a-single-url/#findComment-773733 Share on other sites More sharing options...
daveoffy Posted March 1, 2009 Author Share Posted March 1, 2009 but than how will I access fileid and site. I use to use $_GET but I found that it is unsafe. I need to pull the two numbers in to a query. Quote Link to comment https://forums.phpfreaks.com/topic/147388-solved-htaccess-2x-rewriterules-in-a-single-url/#findComment-773747 Share on other sites More sharing options...
wildteen88 Posted March 1, 2009 Share Posted March 1, 2009 I use to use $_GET but I found that it is unsafe. $_GET is unsafe if you don't validate/sanitise user input correctly. As site and filedid only pass a number it is easy to validate the input. Like so: // check that fileid and site is present in the url // and check to see they contain only numbers. if(isset($_GET['fileid'], $_GET['site']) && is_numeric($_GET['fileid']) && is_numeric($_GET['site'])) { // filedid and site are now safe to use $fileID = $_GET['fileid']; $siteID = $_GET['site']; // rest of your code follows here } Quote Link to comment https://forums.phpfreaks.com/topic/147388-solved-htaccess-2x-rewriterules-in-a-single-url/#findComment-773749 Share on other sites More sharing options...
daveoffy Posted March 1, 2009 Author Share Posted March 1, 2009 Sweet. Thanks everyone who has helped me! Quote Link to comment https://forums.phpfreaks.com/topic/147388-solved-htaccess-2x-rewriterules-in-a-single-url/#findComment-773751 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.