2 Replies - 770 Views - Last Post: 12 October 2015 - 01:01 PM

#1 pfar54   User is offline

  • D.I.C Addict

Reputation: 1
  • View blog
  • Posts: 604
  • Joined: 30-April 15

.htaccess and php forms

Posted 12 October 2015 - 12:17 PM

I have two questions that both relate to each other.

1. Can I have more than one .htaccess file in my hosting server. For example, in the cpanel, if I go to filemanager and select one domain to view the files and it has an .htaccess file and then I go to my filemanager and click on a different domain, can I add an .htaccess file to that site to only affect that domain? The reason I ask is because when I first added on an additional domain to my hosting server, I had to do something to my original .htaccess file in order for that domain to even come up because it was redirecting the new site to the old one.

So recap, can I have an .htaccess file for each domain in my server.


2. When I originally created my .htaccess file, I was attempting to get rid of the .php at the end of my site in the browser bar. So indead of it saying website.com/index.php, I wanted it to say website.com/index. I was able to get this to work, but then my php forms were not working. It would not do anything after I hit submit.

So is there a way to get this to work so that my forms will still work? I currently have this, but if I can create a new .htaccess file under this new domain files, then most of this shouldn't be relevant.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?site2\.com [NC]
RewriteCond %{HTTP_HOST} ^www\.site1\.com [NC]
RewriteRule ^(.*)$ https://site1.com/$1 [R=301,NE,L]
RewriteCond %{HTTPS} ^off
RewriteCond %{HTTP_HOST} !^(www\.)?site2\.com [NC]
RewriteRule ^(.*) https://site1.com/$1 [R=301,NE,L]


<IfModule mod_security.c>
    # Turn off mod_security filtering.  SMF is a big boy, it does not need its hands held.
    SecFilterEngine Off

    # The below probably isn't needed, but better safe than sorry.
    SecFilterScanPOST Off
</IfModule>



I am adding a third site.

Any help would be appreciated! Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: .htaccess and php forms

#2 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6822
  • View blog
  • Posts: 31,459
  • Joined: 10-May 07

Re: .htaccess and php forms

Posted 12 October 2015 - 12:31 PM

View Postpfar54, on 12 October 2015 - 03:17 PM, said:

I have two questions that both relate to each other.

1. Can I have more than one .htaccess file in my hosting server. For example, in the cpanel, if I go to filemanager and select one domain to view the files and it has an .htaccess file and then I go to my filemanager and click on a different domain, can I add an .htaccess file to that site to only affect that domain? The reason I ask is because when I first added on an additional domain to my hosting server, I had to do something to my original .htaccess file in order for that domain to even come up because it was redirecting the new site to the old one.

So recap, can I have an .htaccess file for each domain in my server.

you can have different .htaccess files in different directories, you can also have different directives within .htaccess per domain. You can also move your .htaccess rewrites into the vhost file for that domain.

View Postpfar54, on 12 October 2015 - 03:17 PM, said:

2. When I originally created my .htaccess file, I was attempting to get rid of the .php

So is there a way to get this to work so that my forms will still work?


It's called clean url's & I've seen it done a lot cleaner than what you have there. When I see it, it's simply changing the display of the url int he address bar, so it should never change the way the site operates.
Was This Post Helpful? 0
  • +
  • -

#3 pfar54   User is offline

  • D.I.C Addict

Reputation: 1
  • View blog
  • Posts: 604
  • Joined: 30-April 15

Re: .htaccess and php forms

Posted 12 October 2015 - 01:01 PM

Thank you for your response! My situation was a bit trickier with the original site I created. I wanted all of my pages to have my SSL on them, so I did the https rewrite. Then I wanted to remove the www. for when people came to my site it showed https://site1.com . To be honest I forget exactly what my original issue was, but the code I posted does not have the code to remove the .php because I could never get it to work like I wanted it to, it was causing login issues and that is where the problems came from.

I just added a new .htaccess file to my site number 2 (I'm still waiting on my third site to finish registration). I put this code in the file...

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


And it worked great once I removed the .php from my links. So thank you very much!



Why did I have to do this to my original .htaccess file to get my site2 to come up when searching for it in the browser?

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?site2\.com [NC]
RewriteCond %{HTTP_HOST} ^www\.site1\.com [NC]
RewriteRule ^(.*)$ https://site1.com/$1 [R=301,NE,L]
RewriteCond %{HTTPS} ^off
RewriteCond %{HTTP_HOST} !^(www\.)?site2\.com [NC]
RewriteRule ^(.*) https://site1.com/$1 [R=301,NE,L]


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1