Search code examples
php.htaccessmampserver

404 errors with .htaccess and php files


I keep getting 404 errors when I type.

localhost/shirt.php?id= followed by an number from an array I created

RewriteEngine On
RewriteRule ^shirts/$ /shirts/shirts.php
RewriteRule ^shirts/([0-9]+)/$ /shirts/shirt.php?id=$1
RewriteRule ^receipt.php$ /receipt/ [R=301]
RewriteRule ^contact.php$ /contact/ [R=301]
RewriteRule ^shirts.php$ /shirts/ [R=301]

RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteRule ^shirt.php$ /shirt/%1/? [R=301]

Using MAMP with Chrome and I've cleared my cache multiple times


Solution

  • So after staying up for a couple more hours I've figured it out

    Adding a Trailing Slash to the end of the url

    RewriteRule ^(contact/[a-zA-Z0-9]+)$ /$1/ [R=301]
    

    Rewriting the Rules with Query Strings

    RewriteRule ^contact/([a-zA-Z0-9]+)/$ /contact/index.php?status=thanks
    RewriteCond %{QUERY_STRING} ^status=([a-zA-Z0-9]+)$
    RewriteRule ^index.php$ /contact/%1/? [R=301]
    

    This is what worked for me