mod_rewrite Help

Hi,

This is my htaccess:

RewriteCond %{REQUEST_URI} ^/buy/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^buy/(.+)$ /files/buy/index.php/$1 [L]

This is the path I want to navigate to in my web browser, and it does not work despite the htaccess rule:

/buy/customer/account/login/

This is the other path I go to in my web browser, and it does work, why?

/files/buy/index.php/customer/account/login/

As you can see, my .htaccess should be configured correctly. Am I missing something?

GP,

Okay, with APache 2.0.63, you need to DELETE the red /.

RewriteCond %{REQUEST_URI} ^[COLOR="Red"]/[/COLOR]buy/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^buy/(.+)$ /files/buy/index.php/$1 [L]

Question: Is the files directory within your webspace? If it is, is this .htaccess in your DocumentRoot (directory above files)? If not, delete the start anchor in the RewriteRule, too.

Regards,

DK

GP,

Your mod_rewrite code is written for both Apache 1.x and Apache 2.x - which are mutually exclusive so it will never work as is. Which version are you using? If your’e not sure, replace the ^ (Apache 2.x version) and ^/ (Apache 1.x version) with ^/? as that will work for both versions.

Regards,

DK

GP,

I’m sure that the solution is relatively simple but you’ve not provided sufficient information (nor answered the question about files vs DocumentRoot). It also appears that you have Options +MultiViews enabled so I have to ask for:

  1. Your WEBSPACE’s directory structure (as applies to this question), specifically noting the location of DocumentRoot, files, buy, customer, account and login directories. While you’re at creating this “map,” WHERE is the index.php? I suspect that customer and login are “pseudo” directories of your CMS but that needs to be confirmed.

  2. Show your FULL .htaccess file(s) in the path to index.php and to your login directory.

I’m NOT familiar with Magento but it should work the same as WordPress (where its index.php include()s all relevant modules depending upon the requested URI. That being said, the only thing necessary here is to get the customer/login/ to the index.php file (which should be merely directing to the index.php as it should read the original URI).

Regards,

DK

Does nobody know how to fix this? :\ I thought it looked like a simple Apache problem since the absolute path works but the mod_rewrite path does not.

Hi,

I tried multiple combinations, and here are the results:

^buy/ = 404
^/buy/ = Finds correct file, but same problem
buy/ = Finds correct file, but same problem
/buy/ = Finds correct file, but same problem

In the first result, I get a 404. It isn’t a 404 page, but I have this rewrite rule at the end:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.php?id=$1 [PT,L,QSA]

It just takes me to my /index.php so I’m assuming ^buy/ didn’t work at all since it went to a fallback page.

All the other combinations leads me to the Magento main page, but Magento says it can’t find the file (Magento 404 page) even though when I try it with /files/buy/index.php/url/ it will work. My .htaccess is explicitly telling Apache to go there with just /buy/ instead of /files/buy/index.php/ but it only works with the latter for some reason despite the rewrite rules and regex looking (seemingly) correct.

Hello,

httpd -v shows:

Server version: Apache/2.0.63
Server built: Oct 10 2010 01:54:46
Cpanel::Easy::Apache v3.2.0 rev5193