Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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?