1

I've moved my abc folder from /myproduct/abc directory to /myproduct/extensions/abc on my server.

How can I redirect all calls to http://localhost/myproduct/abc to http://localhost/myproduct/extensions/abc ?

Ex : if requested URL is http://localhost/myproduct/abc/pqr.php, it should be redirected to http://localhost/myproduct/extensions/abc/pqr.php

Basically I want .htaccess code that can be placed inside /myproduct folder and if someone requests URL like http://localhost/myproduct/abc/pqr.php then it will look for occurrence of /abc/ and replace it with /extensions/abc/ We cannot replace /myproduct/abc/ by /myproduct/extensions/abc/ as myproduct can have white-labelled to yourproduct or myproduct1 etc..

Any help would be highly appreciated. :)

5
  • You don't mention if abc and extensions are fixed strings or they can be different in each URL. If they are dynamic, ¿what's fixed in the incoming URL? On the other hand, which URL is entered and displayed in the browser. This one http://localhost/myproduct/abc or this one http://localhost/myproduct/abc/pqr.php ? Commented Jan 24, 2013 at 12:12
  • abc and extensions are fixed strings. Incoming url will be localhost/myproduct/abc/pqr.php then it should redirect to localhost/myproduct/extensions/abc/pqr.php Its not necessary that call to above url will come only from browser. (It can be ajax call etc.) Commented Jan 24, 2013 at 15:03
  • Yes. I understand that. The question is made that way to make it as clear as possible, that's all. Please check my answer. Commented Jan 24, 2013 at 15:33
  • Hello faa, I don't know how your answer disappeared from this post, but it worked as i wanted. Please add your answer so i can rate it and it will be useful for others. Thanks a lot..!! :) Commented Jan 25, 2013 at 9:49
  • I undeleted it. I thought it was of no use as you never said anything again. But, thanks for your message. Commented Jan 25, 2013 at 10:44

3 Answers 3

2

You may try this:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /(.*)/abc/([^\.]+)\.php/? [NC]
RewriteRule .*   %1/extensions/abc/%2.php  [R=301,L]

Redirects

http://localhost/Any/Number/Of/Folders/abc/AnyFileName.php

To:

http://localhost/Any/Number/Of/Folders/extensions/abc/AnyFileName.php

To keep the first URL showing in the browser's addres bar, remove R=301 from [R=301,L]

NOTES:

  1. If only folder myproduct/ is needed, like this: http://localhost/myproduct/abc/AnyFileName.php The rule will work too.

  2. If file AnyFileName.php, pqr.php for example, exists at folder abc in the incoming URL, the rule will be skipped (Makes no sense to have it there anyway). The script has to be at folder abc in substitution URL: http://localhost/Any/Number/Of/Folders/extensions/abc/.

Sign up to request clarification or add additional context in comments.

2 Comments

Its redirecting infinitely as resulting url also contains abc and its again redirecting to \extension\abc. So its redirecting me to localhost/myproduct/extensions/extensions/extensions/extensions/extensions......[infinite]/abc/pqr.php
Updated my answer. Please try again.
0

Vijay,

Try this:

RewriteEngine On
RewriteBase /

# REQUEST_FILENAME should not be file name
RewriteCond %{REQUEST_FILENAME} !-f

# REQUEST_FILENAME should not be directory name
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} /(.*)/abc/(.*)/? [NC]
RewriteRule .*   %1/extensions/abc/%2  [R=301,L]

Comments

0

Which server are you using? Have a look at mod_rewrite in case you are using Apache 2.

http://httpd.apache.org/docs/current/mod/mod_rewrite.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.