views:

82

answers:

1

I have a Godaddy shared Linux hosting account. I assume that for this issue I'll need to rewrite URLs, but my Apache knowledge is quite limited, so please excuse me in advance if the question is too noob-ish :).

for domain xxx.com, I call my PHP web service like this:

http://service.xxx.com/catalog.php?action=getcatalog&catalogid=7

I want to be able to call it like this:

http://service.xxx.com/catalog/getcatalog?catalogid=7

Since I have several services with several parameter names, the variables in this equation are the name of the page, the action and the parameters

(i.e. http://service.xxx.com/X/Y?Z=W => http://service.xxx.com/X.php?action=Y&Z=W) As an added complication, some of those services have more than one parameter.

The questions are: 1. having a shared server with no access to the httpd.conf file, is this even possible? 2. If so, what do I need to do?

TIA, Guy

A: 
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(\w+)/(\w+)$ $1.php?action=$2 [L,QSA]
</IfModule>

the QSA part is supposed to pass any other parameter.

aularon
@aularon thanks for the speedy answer. Where do I place this section? Is it the .htacess file in the specific php file's directory? Do I need to restart the service (which, of course, I can't)?
Traveling Tech Guy
If the same example URLs you posted apply, then put it in the `.htaccess` file in the root of your public folder. and you don't need to restart the service, as apache parses `.htaccess` on every request.
aularon
Doesn't work - I get a 404.
Traveling Tech Guy
I forgot something at first, try now.
aularon
Still get 404. Could it be that mod_rewrite.c does not exist in my GoDaddy account? Or maybe I'm not placing the file properly?
Traveling Tech Guy
To ensure if it exists, change a directive within that `<IfModule mod_rewrite.c>` block into a non-existing directive, for instance `RewriteEngine` INTO `RewriteEngineBlaBlaBla`. if you get `500 Internal Server Error`, then `mod_rewrite.c` is available.
aularon
Thanks for sticking with me :) Your idea worked and I managed to ascertain mod_rewrite.c exists. However, using your syntax, I'm still receiving 404. To be clear, I put your code in a file called .htaccess in the directory. Calling 'catalog.php?action=getcatalog calling '/catalog/getcatalog?catalogid=7' yields a 404
Traveling Tech Guy
I will try with it locally and put what I get here
aularon
aularon
Then it IS a GoDaddy thing then, if it works for you :( Could it have something to do with the htaccess file permissions? It's 644 right now.
Traveling Tech Guy