PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 14, 2022

[FIXED] 404 errors with .htaccess and php files

 February 14, 2022     .htaccess, mamp, php, server     No comments   

Issue

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



Answered By - EliCollins
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing