CentOS 7 Apachect1 Removing a Virtual Host - linux

[SOLVED]
I have a CentOS 7 VPS running Apachect1 and I have just finished a project that required me to create multiple subdomains. Now that I am done I do not need them so I want to go back and clean up a bit.
I had originally created the files
/etc/httpd/sites-available/site1.domain.com.conf
/etc/httpd/sites-available/site2.domain.com.conf
/etc/httpd/sites-available/site(...).domain.com.conf
and
/etc/httpd/sites-enabled/site1.domain.com.conf
/etc/httpd/sites-enabled/site2.domain.com.conf
/etc/httpd/sites-enabled/site(...).domain.com.conf
They were working and everything and all I thought I had to do to remove these domains were to delete those files and restart apache. I did this but I can still access these websites. Any idea?
I ran these commands:
# apachectl restart
# systemctl restart named.service
# systemctl start named
# systemctl enable named
# systemct1 status httpd.service
I have even restarted my server but nothing. Sorry if I missed anything obvious, I am still new to Linux. Thank you for any help.

there are several things you can do.
the first thing is to verify /etc/httpd/conf/httpd.conf to make sure how VIRTUAL HOSTS are defined in you file and if there are declared there.
Centos httpd config file
If there are no VIRTUAL HOST THERE. you will need to make sure that those files do not exist
/etc/httpd/sites-available/site1.domain.com.conf
/etc/httpd/sites-available/site2.domain.com.conf
/etc/httpd/sites-available/site(...).domain.com.conf
You could also try this commands
service httpd stop (to stop service)
service httpd start (to start service)
Let me know if this works :)

SOLVED
So I figured out how to work around this. I am not sure why but the issue was, anytime I went to a non existing subdomain I would get redirected to /var/www/SubdomainA/index.php
The way I worked around this was I went to each of my subdomains and added a rewrite condition in the .htaccess file that said, if the subdomain is not the specified subdomain, then send it to the main site.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www|SubdomainA)\.example\.com
RewriteRule .* http://www.example.com%{REQUEST_URI} [R=301]
Hopefully this will help someone at some point.

Related

Server always adds suffix to url

I was playing around with wordpress on my linux machine, and now I am stuck as when i call the ip address on any browser xxx.xxx.xxx it always gets redirected to xxx.xxx.xxx/wordpress which was a directory below /var/www/html/ where i put all the wordpress files. I must somehow damaged my httpd conf / .htaccess or anything in between. I am not very experienced in those areas, thats why I ask you guys.
How can i disable the permanent addition of a suffix to my systems default url?
Thanks in advance
Is there any Virtual Hosts added to your httpd conf. If yes try removing it

Why won't MAMP let me chage the root folder to something other than default. I get secure connect failed

I have been trying for around a year off and on to use my mac as a development webserver. I keep running into roughly the same problem no matter what platform I use. I've currently installed MAMP however when I set my root directory to my web page I keep getting security issues from whatever browser I'm using. The default root of MAMP works, no problem but when I change it to what I want I get: Secure Connection Failed. Using the MAMP default if there's an http prefix it's just http but when I set my own root the prefix is https://. The "Problem Loading Page" page doesn't give me an option to add a security exception. This is beyond my pitiful brain level to figure out, so I'm hoping much smarter people than me can help me understand what's going on. I guess I could just move my web site to the MAMP default folder but that seems like cheating...
I figured it out, finally. I kept changing the Document Root to directories leading up to httpdocs. Each worked when loading the page until I arrived at the httpdocs directory, at which time I got the security exception and problem loading page. I removed this redirect from .htaccess in htttpdocs -
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This fixed the security exception.

Virtual Host, works but any links get instant 404 error message

I created and setup a LAMP stack, inserted the database + files + code, and went to the local host. The main page pulls up (GOOD!) but, any links on the main page, no matter what it is.. gives me this:
Not Found
The requested URL /user/register was not found on this server.
Apache/2.4.18 (Ubuntu) Server at cbirc.com Port 80
I am assuming this is a apache issue? If someone could fill me in. Its strange that the main page pulls up fine, but any links to any other part of the site gives me this error code.
If index is working, It sound that RewriteEngine was not set to ON in apache configuration, Try to add this to your .htaccess file or vhost (/etc/apache2/sites-available/yourdomaine.com) :
<ifModule mod_rewrite.c>
RewriteEngine On
</ifModule>
If you modify vhost, don't forget to restart apache :
sudo apachectl configtest #Test before restart
sudo apachectl restart
if module is not installed :
sudo a2enmod rewrite
You can also check the Base URL in your HTML if you have one

How can i get mod_rewrite and .htaccess working with cakephp?

I'm trying to get cakephp working locally on my mac - yosemite. I have apache and php working locally in my /~user/Sites directory... I can hit a php ini file ok and have an install of wordpress in another directory.
I've hooked it all up apart from getting the urls rewriting... I followed the steps on the cake site:
http://book.cakephp.org/2.0/en/installation/url-rewriting.html
Now all I get is 404 not found!.
The three .htaccess files have the default content with an additional RewriteBase pointing to the folder its installed in, in my Sites folder.
Any ideas what I'm doing wrong? I've read the other posts on this and none of them helped!
Thanks
First, confirm mod_rewrite is enabled by (on command line):
# a2enmod rewrite
If it just got enabled using the command above, restart apache:
# /etc/init.d/apache2 restart
These types of errors should hit your error.log .. while trying to load the site, hold the error log open:
# tail -f /var/log/apache/error.log
and try to access your page again.
If this doesn't help you solve the problem, paste in your rewrite rules so we can take a peak.

Unable to enable Clean URLs in drupal 7 website after migration

Recently, I migrated my website from local machine to server machine. The website URL is http://www.example.com/myweb
I noticed that only front page is visible and other pages are showing 404 error.
After reading this answer, I got to know that this is happening because of clean URL module. I enabled RewriteBase myweb in .htaccess file but It doesn't work out. Finally I thought of disabling Clean URL temporary as told here. This works well.
Now I wanted to enabled it again. It is showing following error-
Clean URLs cannot be enabled.
Below is the screenshot-
I can see some directory permissions error in status report at admin/reports/status. Are these related to each other?
You need to change your Apache server setting on new server.
Enable 'LoadModule rewrite_module modules/mod_rewrite.so' line in httpd.conf file on your server and restart server
Check if .htaccess works and also check if you have AllowOverrides All in your virtualHost config in Apache.

Resources