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

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

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.

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>

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>

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.