.htaccess mod_rewrite URL query
- by 1001001
I was hoping someone could help me out. I'm building a CRM application and need help modifying the .htaccess file to clean up the URLs. I've read every post regarding .htaccess and mod_rewrite and I've even tried using http://www.generateit.net/mod-rewrite/ to obtain the results with no success. Here is what I am attempting to do.
Let's call the base URL www.domain.com
We are using php with a mysql back-end and some jQuery and javascript
In that "root" folder is my .htaccess file. I'm not sure if I need a .htaccess file in each subdirectory or if one in the root is enough.
We have several actual directories of files including "crm", "sales", "finance", etc.
First off we want to strip off all the ".php" extensions which I am able to do myself thanks to these posts. However, the querying of the company and contact IDs are where I am stuck.
Right now if I load www.domain.com/crm/companies.php it displays all the companies in a list.
If I click on one of the companies it uses javascript to call a "goto_company(x)" jQuery script that writes a form and submit that form based on the ID (x) of the company. This works fine and keeps the links clean as all the end user sees is www.domain.com/crm/company.php. However you can't navigate directly to a company.
So we added a few lines in PHP to see if the POST is null and try a GET instead allowing us to do www.domain.com/crm/company.php?companyID=40 which displays company #40 out of the database.
I need to rewrite this link, and all other associated links to www.domain.com/crm/company/40
I've tried everything and nothing seems to work. Keep in mind that I need to do this for "contacts" and also on the sales portion of the app will need to do something for "deals".
To summarize here's what I am looking to do:
Change www.domain.com/crm/dash.php to www.domain.com/crm/dash
Change www.domain.com/crm/company.php?companyID=40 to www.domain.com/crm/company/40
Change www.domain.com/crm/contact.php?contactID=27 to www.domain.com/crm/contact/27
Change www.domain.com/sales/dash.php to www.domain.com/sales/dash
Change www.domain.com/sales/deal.php?dealID=6 to www.domain.com/sales/deal/6
(40, 27, and 6 are just arbitrary numbers as examples)
Just for reference, when I used the generateit.net/mod-rewrite site using www.domain.com/crm/company.php?companyID=40 as an example, here is what it told me to put in my .htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^crm/company/([^/]*)$ /crm/company.php?companyID=$1 [L]
Needless to say that didn't work.