Forum
.htaccess and the Forms app
Hi Drew/Rachel,
I am using .htaccess to rewrite the php file extension to an extension less version e.g. www.sitename.com/example.php becomes www.sitename.com/example. Here is the code:
# Rewrite .php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]
This works but I am trying to redirect any direct traffic to the .php version of the url to the version without the extension using the following in .htaccess:
# Redirect to .php-less link if requested directly
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteRule ^(.+)\.php $1 [R=301,L]
This also works BUT the forms app no longer submits a form. Obviously my code is affecting the files in the forms app preventing it from working properly. Is there a way to avoid this issue?
Thanks, Andy
Sounds like you're redirecting the form submission. Check the
action
attribute on your forms - does it look correct?Hi Drew,
I am not using an
action
attribute as the form is handled by Perch. Here is the form code:But an
action
attribute is being output. Have you checked its value?No I haven't, how would I do that? Using debug?
FYI - if i remove the below, the form submits correctly:
You would view source on your web page and look at the form tag that is being output.
Hi Drew,
I'm presuming you're then redirecting
/contact.php
to something else? When you do that the posted data is thrown away.On your form, set
action="/contact"
or whatever you need it to be.Yes,
/contact.php
redirects to/contact
. I see, so the post data is discarded as the page has been redirected away to in effect a different page.I added
action="/contact"
as you suggested and that solved the problem, thanks Drew.