简体   繁体   中英

Localhost htaccess not working

I've got the following .htaccess which is not working:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /coffee_shop/

# For sales:
RewriteRule ^shop/sales/?$ sales.php

# For the primary categories:
RewriteRule ^shop/(coffee|goodies)/?$ /shop.php?type=$1

# For specific products:
RewriteRule ^browse/(coffee|goodies)/([A-Za-z\+\-]+)/([0-9]+)/?$ browse.php??type=$1&category=$2&id=$3

# For shop:
RewriteRule ^shop/([A-Za-z\+]+)/?$ shop.php?type=$1

</IfModule>

When I access http://localhost/coffee_shop/html/shop/goodies is supposed to be translated to http://localhost/coffee_shop/html/shop?type=goodies but that's not the case. I'm getting a 404 Object Not Found error so the file is getting read (I put some garbage code in it and resulted in a 500 error).

  1. The folder structure is:
    • htdocs/ -project1/ -project2/ -coffee_shop/

I don't want to move the .htaccess to the root because I might use a different .htaccess in some other project.

  1. Yes, AllowOverride is set to All in httpd.conf

  2. Tried adding to httpd.conf <Directory /Applications/XAAM/htdocs/coffee_shop>AllowOverride All</Directory> but it didn't work.

Any suggestions?

Thanks.

To me it looked like you were missing the "html" part to your rewrite rules - it was referenced in the urls but not the rule - hence 404

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /coffee_shop/

    # For sales:
    RewriteRule ^html/shop/sales/?$ sales.php

    # For the primary categories:
    RewriteRule ^html/shop/(coffee|goodies)(/?)$ shop.php?type=$1

    # For specific products:
    RewriteRule ^html/browse/(coffee|goodies)/([0-9]+)(/?)$ browse.php?type=$1&id=$2

    # For shop:
    RewriteRule ^html/shop/([A-Za-z\+]+)(/?)$ shop.php?type=$1

</IfModule>


http://localhost/coffee_shop/html/shop?type=goodies can be accessed via  http://localhost/coffee_shop/html/shop/goodies

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM