Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Lauren Clark
Lauren Clark
33,155 Points

Broke PHP Contact form using .htaccess Clean URLS

Using the contact form code from the PHP Simple Application Course

It was all working wonderfully until I decided to clean up the URL's with .htaccess

Here's my htaccess code.

# REWRITES
# Canonical
RewriteEngine on
#RewriteCond %{HTTP_HOST} ^site\.co.uk$ [NC] RewriteRule ^(.*)$ http://www.site.co.uk/$1 [R=301,L] RewriteCond %{THE_REQUEST} ^.*/index.html
#RewriteRule ^(.*)index.php$ http://www.site.co.uk/$1 [R=301,L]

#prettyurls
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

#index to root
RewriteCond %{THE_REQUEST} ^.*/index\.php 
RewriteRule ^(.*)index.php$ /$1 [R=301,L]

This has since broken the submit, when I submit the form it comes back to site/contact and the page is blank.

Previously it would append the contact.php with php?status=thanks and change the message with the if statement as normal.

I've tried removing the php part here

    header("Location: contact.php?status=thanks");
    exit;
}
//Changed the above to this
    header("Location: contact?status=thanks");
    exit;
}

Do I need some kind of negator? The URLs work with or without the .php and I've tried starting the page as contact.php too, so it can go back to .php, but it always ends up at /contact without the php extension and a blank page.

Any help would be much appreciated :)

Jacques Vincilione
Jacques Vincilione
17,292 Points

Can you post your contact.php code?