#1
|
||||
|
||||
Any .htaccess experts out there?
I'm struggling a bit getting my .htaccess settings correct and was wondering if there are any .htaccess experts out there. If so, please contact me.
TIA. |
#2
|
|||
|
|||
I can help, but generally suggest adding config to the Apache vhost config rather than using .htaccess. However if .htaccess is what the hosting company supports, that's fine too. Assuming you're trying to redirect http to https, this is one of the simpler ways to do it.
Code:
<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://forums.thepaceline.net/$1 [R,L] </IfModule> Code:
sudo a2enmod rewrite sudo service apache2 restart Code:
[rkhatibi ]$ curl -I http://twitter.com HTTP/1.1 301 Moved Permanently content-length: 0 date: Mon, 24 Apr 2017 23:45:12 GMT location: https://twitter.com/ [rkhatibi ]$ curl -I http://twitter.com/search HTTP/1.1 301 Moved Permanently content-length: 0 date: Mon, 24 Apr 2017 23:45:14 GMT location: https://twitter.com/search |
#3
|
||||
|
||||
Thanks so much for the reply!!! The other thing that I want to do is redirect www.thepacelinet.net to forums.thepaceline.net.
Here is my current .htaccess... Quote:
Quote:
For now, I went back to the original .htaccess settings and you can access the site from both http and https. When I used the new .httaccess file, I can see that not many users can get to the forum. Do you see something wrong in the modified .htaccess file that would cause this problem? I'll have to check our host company regarding the Apache host config modifications. |
#4
|
|||
|
|||
It's redirecting so server config should be good. Just wanted to give you options on testing it. Often hard to tell what's going on within the server.
I think what we have is two separate sets of redirects. RewriteCond %{SERVER_PORT} 80 is grabbing any http traffic that comes in including http://forums. Then redirecting it to https://www, then it hits a redirect from http(s)://www to http://forums and finally https://. Maybe. I'd try the following to send traffic directly to https://forums and hopefully skip any other actions. Code:
Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://forums.thepaceline.net/$1 [R=301,L] RewriteCond %{HTTP_HOST} . RewriteCond %{HTTP_HOST} ^www\.thepaceline\.net RewriteRule (.*) https://forums.thepaceline.net/$1 [R=301,L] order allow,deny |
#5
|
||||
|
||||
rkhatibi -- Thanks again for the reply and information. I'll give this a try in the morning. I especially appreciate the tip on how to test this...that will make things a lot easier. I assume I can test this on the Linux server this site is running on...correct?
|
#6
|
|||
|
|||
Yep you can run those tests from the server itself.
If you have console access to the server and can change the Apache config there are a few other things you can look at. This should list the vhost files. You can look directly at them to see if there are other rewrite rules in effect Code:
ls -la /etc/apache2/sites-enabled/ less /etc/apache2/site-enabled/www.thepaceline.net.conf # or whatever the file name is Code:
RewriteLog /var/log/apache2/rewrite.log RewriteLogLevel 3 |
#7
|
||||
|
||||
I do have access to a console on the server and can view the files in the directory you listed. There are a number of *.conf files in there, but I'm not sure what to check for in these files for the rewrites. I haven't played around with these files before, so I'm a newbie
|
#8
|
|||
|
|||
hahah, alright you're getting a class in Linux webserver administration 101.
in /etc/apache2/sites-enabled/ there are probably 4-5 files. I'd suspect default.conf, www.conf, and forums.conf or something similar. The default is installed as part of the Apache package IIRC. Anything else should be added by you, vbulletian, or the hosting provider. I prefer naming the config files after the site they represent, forums.thepaceline.net.conf etc, but it's by no means universal. I'd look at each one to see what you have there may be a mix of general config and Apache vhosts. The top of the file will probably look like this. Code:
/etc/apache2/sites-enabled/99_some_file.conf <VirtualHost *:80> ServerName somesite.example.com DocumentRoot /var/www/sitesite #bunch of other stuff The next step is to look for rewrite rules within the Apache vhost files and map the behavior of the rewrite rules out per ServerName or ServerAlias. I suspect there is a www.thepaceline.net config that has rewrite rules already in it and this is causing the problems you're seeing. There's a fair amount of information there and happy to explain more if you have questions. Lastly after you understand what's going on, I'd recommend simplifying the config. Maybe remove any www specific config, I believe forums is the only site on the machine, and make things look roughly like the following Code:
keith@yourserver ~ $ cd /etc/apache2/sites-enabled/ keith@yourserver /etc/apache2/sites-enabled $ ls -l total 12 -rw-r--r-- 1 root root 2824 Mar 13 18:40 00_default.conf -rw-r--r-- 1 root root 821 Apr 10 14:10 90_forums.conf -rw-r--r-- 1 root root 821 Apr 10 14:10 99_redirect.conf keith@yourserver /etc/apache2/sites-enabled $ cat 90_forums.conf <VirtualHost *:443> ServerName forums.thepaceline.net ServerAlias www.thepaceline.net # Force all requests to https://forums.thepaceline.net RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.thepaceline\.net$ [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/(.*) https://forums.thepaceline.net/$1 [L,R=301] # etc etc docroot, ssl, logging and so forth keith@yourserver /etc/apache2/sites-enabled $ cat 99_redirect.conf <VirtualHost *:80> ServerName forums.thepaceline.net ServerAlias www.thepaceline.net # /var/empty should work, you're serving no files DocumentRoot /var/empty ErrorLog /var/log/apache2/redirector-error.log TransferLog /var/log/apache2/redirector-access.log LogLevel error # *any* traffic to this vhost gets redirected # basically the same as the other stuff, just a one liner RewriteEngine On RewriteRule ^(.*) https://forums.thepaceline.net%{REQUEST_URI} [QSA,R=301,NC,L] Feel free to DM or email me config files too if that makes it easier. Always hard when you don't now exactly what you're looking at. |
|
|