Danny620 Posted April 16, 2012 Share Posted April 16, 2012 I have a url like this http://api.socialnewsoffice.com/index.php?get_categories=&api_key=b5cbd66dca99c49d1a6c3d which outputs a json file with categories is there a way to make the url like this http://api.socialnewsoffice.com/get_categories?api_key=b5cbd66dca99c49d1a6c3d thanks Quote Link to comment https://forums.phpfreaks.com/topic/261027-mod_rewrite/ Share on other sites More sharing options...
Danny620 Posted April 16, 2012 Author Share Posted April 16, 2012 any help? Quote Link to comment https://forums.phpfreaks.com/topic/261027-mod_rewrite/#findComment-1337769 Share on other sites More sharing options...
requinix Posted April 16, 2012 Share Posted April 16, 2012 Calm down, it's only been 30 minutes on an early Monday morning. Yes it's possible. In a .htaccess: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} ^/(get_categories|...)\? RewriteRule ^ index.php?%1= [L,QSA] For every API call to do URL rewriting on, add it to that third Cond separated by |s. Like ^/(foo|bar|baz|whatever)\? (If anyone's wondering, I used a third RewriteCond for readability's sake.) Quote Link to comment https://forums.phpfreaks.com/topic/261027-mod_rewrite/#findComment-1337783 Share on other sites More sharing options...
Danny620 Posted April 16, 2012 Author Share Posted April 16, 2012 Hi this doesn't seem to be working? Quote Link to comment https://forums.phpfreaks.com/topic/261027-mod_rewrite/#findComment-1337814 Share on other sites More sharing options...
AyKay47 Posted April 16, 2012 Share Posted April 16, 2012 Hi this doesn't seem to be working? should, can you post the code that you are using please. Quote Link to comment https://forums.phpfreaks.com/topic/261027-mod_rewrite/#findComment-1337818 Share on other sites More sharing options...
Danny620 Posted April 16, 2012 Author Share Posted April 16, 2012 <IfModule mod_rewrite.c> Options +FollowSymLinks Options +Indexes RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{REQUEST_URI} ^/(get_categories|...)\? RewriteRule ^ index.php?%1= [L,QSA] RewriteRule ^([^\.]+)/$ $1.php [NC,L] </IfModule> Quote Link to comment https://forums.phpfreaks.com/topic/261027-mod_rewrite/#findComment-1337821 Share on other sites More sharing options...
Danny620 Posted April 16, 2012 Author Share Posted April 16, 2012 and im trying to access http://api.socialnewsoffice.com/get_gategories?api_key=b5cbd66dca99c49d1a6c3d Quote Link to comment https://forums.phpfreaks.com/topic/261027-mod_rewrite/#findComment-1337823 Share on other sites More sharing options...
Danny620 Posted April 16, 2012 Author Share Posted April 16, 2012 Ive also put the .htaccess file in public_html should i put it in api folder? Quote Link to comment https://forums.phpfreaks.com/topic/261027-mod_rewrite/#findComment-1337825 Share on other sites More sharing options...
AyKay47 Posted April 16, 2012 Share Posted April 16, 2012 root dir is fine, requinix rewriteCond was an example, RewriteCond %{REQUEST_URI} ^/(get_categories|...)\? It was not meant to be copied verbatim, if you do not have any other conditions to rewrite, leave it as get_categories instead of (get_categories|...) remove the extra newlines in the .htaccess, they should not be there. you have conflicting rewriterules as well, quite frankly the one you added makes no sense to me as to why it is there, use the rewriterule that requinix provided. Quote Link to comment https://forums.phpfreaks.com/topic/261027-mod_rewrite/#findComment-1337828 Share on other sites More sharing options...
Danny620 Posted April 16, 2012 Author Share Posted April 16, 2012 please could you should me an example of how to get from http://api.socialnewsoffice.com/index.php?blog_posts=&api_key=b5cbd66dca99c49d1a6c3d to http://api.socialnewsoffice.com/blog_posts?api_key=b5cbd66dca99c49d1a6c3d thanks for the help btw Quote Link to comment https://forums.phpfreaks.com/topic/261027-mod_rewrite/#findComment-1337831 Share on other sites More sharing options...
AyKay47 Posted April 16, 2012 Share Posted April 16, 2012 re-read requinix post, he gives an answer to this. For every API call to do URL rewriting on, add it to that third Cond separated by |s. Like Code: [select] ^/(foo|bar|baz|whatever)\? Quote Link to comment https://forums.phpfreaks.com/topic/261027-mod_rewrite/#findComment-1337843 Share on other sites More sharing options...
Danny620 Posted April 16, 2012 Author Share Posted April 16, 2012 Ive tried this but no luck <IfModule mod_rewrite.c> Options +FollowSymLinks Options +Indexes RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{REQUEST_URI} ^/(get_categories)\? RewriteRule ^ index.php?%1= [L,QSA] </IfModule> Quote Link to comment https://forums.phpfreaks.com/topic/261027-mod_rewrite/#findComment-1337847 Share on other sites More sharing options...
Danny620 Posted April 16, 2012 Author Share Posted April 16, 2012 please see http://api.socialnewsoffice.com/get_categories? Quote Link to comment https://forums.phpfreaks.com/topic/261027-mod_rewrite/#findComment-1337848 Share on other sites More sharing options...
Danny620 Posted April 16, 2012 Author Share Posted April 16, 2012 any help please? Quote Link to comment https://forums.phpfreaks.com/topic/261027-mod_rewrite/#findComment-1337879 Share on other sites More sharing options...
Danny620 Posted April 19, 2012 Author Share Posted April 19, 2012 Hi, Thanks for all the help already, I have a url like this http://api.socialnewsoffice.com/index.php?get_gategories=&api_key=b5cbd66dca99c49d1a6c3d which when accessed it produces a json output. as you can see the url is a sub domain and the index.php file is in a folder in root public_html called "api" what i would like to achieve is this http://api.socialnewsoffice.com/get_gategories?api_key=b5cbd66dca99c49d1a6c3d I've tried this but no luck also tried the above <IfModule mod_rewrite.c> Options +FollowSymLinks Options +Indexes RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^([^\.]+)/$ $1.php [NC,L] RewriteRule ^/(get_categories)\?$ index.php?get_categories=$1 [L] </IfModule> Quote Link to comment https://forums.phpfreaks.com/topic/261027-mod_rewrite/#findComment-1338736 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.