0

I'm trying to achieve the following:

An HTTP request made to subdomain.domain.com/some/path should be rewritten to domain.com/subdomain/api.php?__route__=some/path.

This is the requirement in order for the Epiphany library to function and properly process RESTful API calls. My website is currently hosted on GoDaddy and I have setup subdomain.domain.com to point to domain.com/subdomain using the GoDaddy web interface. I have placed the following text in the .htaccess file under the subdomain directory:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ api.php?__route__=/$1 [L,QSA]

I'm getting the standard 500 Internal Server Error when I try to make any calls to the RESTful API.

Unfortunately, I have to wait several hours before GoDaddy gives me access to any Apache log files. Any ideas why this isn't working?

EDIT

In order to clarify, I want the following rewriting to take place:

internal.ledworld-me.com/some/path => ledworld-me.com/internal/api.php?__route__=/some/path

Right now, GoDaddy is being used to map internal.ledworld-me.com to ledworld-me.com/internal. I'm starting to think I should remove the mapping from the GoDaddy side and rely solely on mod_rewrite in order to achieve this.

faridghar
  • 1,445
  • 2
  • 13
  • 25

1 Answers1

0

Put this code in your DOCUMENT_ROOT/internal/.htaccess file:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ api.php?__route__=/$1 [L,QSA]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Now I get "The requested URL `/subdomain/some/path` was not found on this server". It seems URL rewriting is not taking place. In order to clarify things and make the question less generic, the domain is ledworld-me.com and the subdomain is internal.ledworld-me.com. So what I want is that when a request is made to internal.ledworld-me.com/path it should be rewritten to ledworld-me.com/internal/api.php?__route__=/path. Please also note that the mapping of the subdomain internal.ledworld-me.com to ledworld-me.com/internal has already been setup via the GoDaddy web interface. – faridghar Jan 17 '14 at 19:34
  • Can you whether both domains are sharing same `DocumentRoot`? – anubhava Jan 17 '14 at 19:37
  • Yes, internal.ledworld-me.com is mapped to ledworld-me.com/internal (via GoDaddy), so they share the same DocumentRoot. – faridghar Jan 17 '14 at 19:46
  • Should I turn off the mapping of internal.ledworld-me.com to ledworld-me.com/internal from GoDaddy or leave it in place? – faridghar Jan 17 '14 at 20:35
  • I think that should be turned off and `DocumentRoot` needs to be same for both domains. – anubhava Jan 17 '14 at 20:40
  • Hi @anubhava, nothing will work. I've reduced the requirements (for now) to just performing simple subdomain rewriting i.e. internal.ledworld-me.com/test.html => ledworld-me.com/internal/test.html. I placed the following in my .htaccess file under the web root: RewriteEngine on RewriteCond %{HTTP_HOST} ^([^.]+)\.ledworld-me\.com [NC] RewriteRule (.*) /%1/$1 [R,L] but i simply get: Oops! Google Chrome could not find internal.ledworld-me.com Can you help me just set up this simple rewriting first? – faridghar Jan 18 '14 at 10:26
  • If you're getting `Google Chrome could not find internal.ledworld-me.com` that means probably `internal.ledworld-me.com` DNS isn't valid. Can you ping `internal.ledworld-me.com`? – anubhava Jan 18 '14 at 18:21
  • I have added a CNAME record in DNS and the ping is returning the correct host IP address. I no longer get the "could not find internal.ledworld-me.com" error but here is where I stand right now is: 1. internal.ledworld-me.com/test.html works (if test.html actually exists) 1. internal.ledworld-me.com/some/path causes a 404 not found error (if some/path does not exist). This makes sense seeing as my .htaccess file is now empty. It is GoDaddy that is doing all the rewriting at this point and I have absolutely no clue what to put in my .htaccess file to get this to work. – faridghar Jan 18 '14 at 18:42
  • Ok good alteast that first hurdle is gone. Now do you want `internal.ledworld-me.com/some/path ` to be redirected to `ledworld-me.com/some/path`? Will `ledworld-me.com/some/path` not cause 404? – anubhava Jan 18 '14 at 18:45
  • Since `internal.ledworld-me.com/some/path` doesn't actually exist, it should be rewritten as `ledworld-me.com/internal/api.php?__route__=/some/path`. This should only happen when /some/path doesn't exist. – faridghar Jan 18 '14 at 19:03
  • ok good, that is exactly what above rule of mine is already doing. It will only rewrite when /some/path doesn't exist. – anubhava Jan 18 '14 at 19:09
  • It doesn't work. I'm getting "The requested URL /internal/some/path was not found on this server." This means that one of the RewriteCond's is not being met and I think it is the first RewriteCond in your code above. The condition is testing if the HOST equals `internal.ledworld-me.com`, but this will never be the case because GoDaddy has rewritten it to `ledworld-me.com` as part of the subdomain mapping no? – faridghar Jan 18 '14 at 19:33
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/45551/discussion-between-faridghar-and-anubhava) – faridghar Jan 18 '14 at 19:33
  • Sorry just came back online. I am not sure if Godaddy will have host part rewritten to `ledworld-me.com`. What URL do you see in your browser after not found error? – anubhava Jan 19 '14 at 06:49