Reputation: 21
I've spent the last 24 hours looking for solutions to my problem both here and by searching google but I've been unable to find anything. Sorry if this is duplicated anywhere however.
For the last version of my site, written in php, I just had one index page which I used requests like this to grab the correct page:
?public=view/thispage
?page=account/loggedin
I'm now writing the new version of the site, also in php, and I'm trying to make it have search engine friendly urls / slugs for example
/page/view/thispage
/account/login
I've managed to get it so that virtual subdomains work for each client, using the top portion of the code below, and I've managed to get the slug pages to work using the bottom portion.
The problem I'm having is with forms, such as the form to sign up for the site, edit a user profile etc. I've read on this site that with apache rewrites $_POST variables should be passed to the script, unlike with redirects, but I'm using rewrite and when any form data is passed to a slug (for example /profile/edit) it doesn't work, although if it's passed to virtualsubdomain.mydomain.com/test.php for example it does.
Can anybody help me out and find a way to fix the htaccess file below and allow $_POST vars to be passed to my slug script (index.php in the code below)? There's probably just a small thing I'm missing.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomainhere.org
RewriteCond %{HTTP_HOST} ^(.+).mydomainhere.org/^(.+)
RewriteRule ^([^/]*)$ http://mydomainhere.org [P,L]
ErrorDocument 404 /index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php
</IfModule>
I can't work out why post vars can be read by php files that exist in the subdomains that are only virtual, but they can't be read when post them to a slug (such as /profile/editprofile). Global variables are off on my server but The following just brings up the default blanked variable so they obviously havent been passed.
$test = ''; //define the variable to please global vars off
$test = $_POST["namehere"];
echo $test;
Any help would be appreciated. I'm fairly new to using htaccess files for anything other than just including a custom error file as you can probably tell.
Upvotes: 1
Views: 467
Reputation: 16065
I'm only guessing because of Your .htaccess RewriteCond
and other people having the same problem - You redirect any subdomain (except www
or URL not containing www.
) to your domain URL without www.
- if I get it right:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomainhere.org
RewriteCond %{HTTP_HOST} ^(.+).mydomainhere.org/^(.+)
RewriteRule ^([^/]*)$ http://mydomainhere.org [P,L]
Then in Your forms You probably have URLs in action
attribute tha do not contain www.
therefore this action URLs gets redirected and the POST is probably lost...
Try to fill Your form action
attribute with URLs containing www.
:
<form method="POST" action="http://www.mydomainhere.org/my_page_to_post_to.php">
Maybe this will help...
Upvotes: 1