Jump to content

mod_rewrite


Danny620

Recommended Posts

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.)

Link to comment
Share on other sites

<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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.