Forum Moderators: phranque
I have a problem which I am sure is small, but for me has turned into a very late night of trying to get this working, and I was wondering...hoping...praying someone wouldn't mind giving me some help.
On our company website, I want to have URLs that would be like www.example.com/parts/randompartnumber.html
So, I proceeded to write the rule in .htaccess like this...
RewriteEngine On
RewriteRule ^parts/(.*).html part.php?search=$1
...and then placed a part.php file in the /parts directory and changed the links to have ../ in front.... That works great....
Then I come to our other site which is hosted by 1and1 and tried to do the same, but it didn't work. Found out that I need to put in
RewriteBase /
Ok, so now it works, however, changing the links in the parts.php file to ../ doesn't work....it still tries to reference to the /parts directory. Not wanting to load the whole website into /parts and feeling sure there must be a better way, I read about and tried several different rules including RewriteCond statements, but no real success.
I now have...
RewriteEngine on
RewriteBase /
RewriteRule parts/(.*).html <part.php?search=$1
Which works to redirect a written URL in the form of www.example.com/parts/partnumber.html to the php in the root directory and search fine, but it does not rewrite it...that is, the URL displayed is still written as www.example.com/part.php?search=partnumber
I am sorry, I have a feeling this is super simple, but I am totally missing the solution so far.
Thanks SO much for your help!
Angus
RewriteEngine On
RewriteRule ^parts/(.*)\.html$ /part.php?search=$1 [L]
RewriteRule ^parts/(.*)$ /$1 [L]
Note that the code (as written) goes into .htaccess in the directory above "/parts" and "part.php" goes in that directory as well. If "part.php" is placed in the "/parts" subdirectory, you'll need to explicitly exclude "parts.php" from being rewritten (to itself) by the second rule. It is already implicitly excluded from the first rule, though, because it doesn't end with ".html".
Jim
Jim