How to create htaccess fiel in api link - .htaccess

I created API by using PHP.
My API link is
http://localhost/phpworkspace/api_testing/api.php
I want to clean my API link by using .htaccess file like
http://localhost/api/v1/retrieve.json
I created various htaccess file. But I can't get. How can I do that? Please help me kindly.

Create .htaccess file in your www directory and paste the following code into the .htaccess file
RewriteEngine On
RewriteRule ^api/v1/retrieve\.json$ /phpworkspace/api_testing/api.php [L]

This ought to do what you want
RewriteEngine On
RewriteRule ^api/v1/retrieve.json$ /phpworkspace/api_testing/api.php [NC]

step 1 : On rewrite mod
step 2 : put code in .htaccess file
.htaccess file
RewriteEngine On
RewriteBase /api_testing
RewriteRule ^api/([.*]+)/$ /api_testing/api.php [L,QSA]

Related

redirect url from htaccess file

I'm trying to bulk redirect my site link like this,I need to remove home from every link and redirect it to root directory as shown below.
example.com/home/hello-world.
example.com/home/tag/world.
to
example.com/hello-world
example.com/tag/world.
I'm using these code
RewriteEngine On
RewriteCond %{REQUEST_URI} (.+)/home(.*)$
RewriteRule ^ %1/ [R=301,L]
Considering that your htaccess rules file have more rules apart from your shown ones, which will take care of handling pages from backend(rewrite), if this is the case then please try following htaccess rules file.
Please these rules at top of your htaccess rules file. Also make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /example.com/
RewriteRule ^home/(.*)$ /$1 [R=301,L]

Changing stylesheet url using .htaccess 2

I have very specific question, I want to solve it using .htaccess and mod_rewrite, I want to make rule in .htaccess file using mod_rewrite, so when somebody visit my site ex.
mysite.com , mysite.com/css/style.css file should be read from other location mysite.com/version1/css/style.css, if I say it otherwise, style.css should not be "picked up" from root folder, but sub-folder.
Try adding this to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$ [NC]
RewriteRule ^css/(.*)\.css$ /version1/css/$1.css [L]

.htaccess subfolder not working

I've looked everywhere to try and solve this and I can't get any of the solutions elsewhere to work.
I have a drupal website running on a domain
I have build a new website in www.domain.com/subfolder
In a .htaccess file in the sub folder:
RewriteEngine On
RewriteRule ^/?login$ /index.php?get_action=login [L]
However when I try and visit www.domain.com/subfolder/login I get redirected to the www.domain.com.
I need www.domain.com/subfolder/login to redirect to www.domain.com/subfolder/index.php?get_action=login
How do I accomplish this.
Please help.
I would make use of drupal and instead of using the .htaccess file , I would install Drupal's Login destination module . You can find it here -> http://drupal.org/project/login_destination . I hope it helps .
If your htaccess file is in the subfolder, you can try adding a rewrite base and remove the leading slashes:
RewriteEngine On
RewriteBase /subfolder/
RewriteRule ^login$ index.php?get_action=login [L]
Or, you can explicitly make the target an absolute URL:
RewriteEngine On
RewriteRule ^/?login$ /subfolder/index.php?get_action=login [L]

.htaccess rewrite resulting in 404 error

I am trying to create search engine friendly URLs with the following .htaccess and it is directing to a 404 error page no matter what I try.
This is on a Host Gator shared account, if it makes any difference. The directory is (document root)/blog, the .htaccess file is located in the directory "blog."
Example URL would be http://examplesite.com/blog/category/announcements.Here is the .htaccess file contents:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9]+)/$ index.php?category=$1
Any ideas why this is happening?
RewriteRule ^category/([a-zA-Z0-9]+)/*$ index.php?category=$1 [R=301,L]
Forget the preceeding slash?
RewriteRule ^category/([a-zA-Z0-9]+)/$ /index.php?category=$1

.htacess redirect

This may seem like a basic question, but I am not getting how to do it. Here is the Urls below.
Old Url : http://domain.com/index.php/items/view/item_name
New Url : http://domain.com/index.php/items/details/name/item_name
How do I do a permanent redirect with this set of old and new Urls in htaccess?
Put this code in your DOCUMENT_ROOT's .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(items)/view/(.*)$ /$1/details/name/$2 [NC,L,R=301]
The following worked for me....
upload a .htaccess file to the folder where ur file exists with the following data (it should be on a new line in the htaccess file)
redirect 301 /some_dir/oldpage.htm http://www.newdomain.com/newpage.htm
and from what i read somewhere when you need to do the same for a dynamic page you can use the following
consider the page as
http://www.example.com/page.php?id=13
the redirect would be
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=13$
RewriteRule ^/page.php$ http://www.example.com/newname.htm? [L,R=301]
here is what i got on googling for this
http://www.tamingthebeast.net/articles3/spiders-301-redirect.htm

Resources