Finding Mod_Rewrite Rules on Cent OS Server - apache

I am having a bit of a problem finding some mod_rewrite details. I am taking over from another PHP web developer. I am used to Ubuntu servers and I am migrating a few sites onto a new Ubuntu server. The old server is CentOS. The old developer used mod_rewrite rules and as they're rather specific, I'm trying to track them down on the server but cannot find them for the life of me. I know it's a bit of a needle in a haystack question but does anyone know where they could be? I've looked within the individual sites var/www/vhost/SITENAME/ config. Not in there. I've looked in the etc/httpd config files too and they're not there. They are also not stored on the file server within htaccess. Thanks for any guidance

Usually the VirtualHost config files are under /etc/httpd/conf.d/.
What you could do is grep -ri rewriterule /etc/httpd/conf*|more to see if the RewriteRules are defined anywhere within the configuration directories.
You should also check grep -i include /etc/httpd/conf/httpd.conf to see if configurations are included from somewhere besides the default Include conf.d/*.conf.

Related

Correct Apache Configuration And Htaccess

I've just reset my Ubuntu 14.04 LAMP server hosted with digital ocean. Could someone tell me the 'proper' way to do server configuration. My goal is to do everything as clean as possible (and hopefully well structured).
I intend on using the server mainly for programming and data analytics, however I do plan on hosting my website in /var/www/html. I also plan on using letsencrypt/certbot to get an easy SSL. With this in mind, these are the main goals I would like to accomplish:
1) Redirect the website to ALWAYS be served through https AND www.
2) Enable HSTS for the entire website.
3) Enable clean url's (remove .php extensions and what not).
Since I would like all of these properties to be used across the entire website, should the configuration be done inside of the /etc/apache2/ folder? Or should it be done inside of .htaccess?
And if it should be done inside of apache2 configuration, which file should I add it to? And finally, how exactly should it be added? (for example vhost 80/443, inside of a mod_something section, etc).
Thank you in advance, I would appreciate and consider any advice about Apache and htaccess!

Can I use yum to install an additional apache httpd server?

I'm using a plain apache server as a front-end and a mod-perl enabled apache server as a backend with mod_proxy.
I'm in the process of moving to a new hosting company so I'm installing software. In the past I've built both of these from source but it would be easier to use yum to install so that they are easily updated. Is it possible to install 2 separate httpd servers with yum? And if so how?
I'm thinking that the solution might be to move the front-end to lighttpd or similar but I'd still like to know whether it is possible.
I'm using Centos 7.
Seem to have it working now. Hope this might help someone else.
I now have one httpd with two different configuration files in /etc/httpd/conf/: httpd_docs.conf and httpd_perl.conf
Set the PidFile to two different files at the top of the config files.
Copied the /etc/httpd/conf.modules.d to /etc/httpd/conf.modules.perl and updated the 'Include' in the two config files to point to the different directories and then deleted unnecessary files in each directory so that the httpd_docs instance does not use mod_perl and the httpd_perl instance does.
Copied /etc/sysconfig/httpd to /etc/sysconfig/httpd_perl and edited each one to include an OPTIONS line
OPTIONS="-d /etc/httpd -f conf/httpd_docs.conf"
and
OPTIONS="-d /etc/httpd -f conf/httpd_perl.conf"
Copied /usr/lib/systemd/system/httpd.service to /usr/lib/systemd/system/httpd_perl.service and edited to point to correct EnvironmentFile.
Used this question to help answer my own question
https://serverfault.com/questions/31838/can-rhel-4-have-two-instances-of-apache-httpd-running-using-two-different-config

How can i know if my apache server is using .htaccess or not?

I want to know if my Apache server uses .htaccess files or not. If it uses them, then why and how?
How can I know if my Apache server is using .htaccess or not?
Thank you.
As for why, it's a convenient way for shared-hosting providers to give some access to users who would like to set some configuration options. You obviously wouldn't want everyone to have access to the main configuration file for security purposes. It's also useful for development purposes since you can set different options for different directories.
As for how Apache uses the file, I recommend reading the documentation.
As for how to know if Apache is using .htaccess files, it most likely is. I've yet to meet a shared hosting provider that doesn't. And if you are running your own server, I assume you would know how you set it up. Worst case scenario, you could follow this advice from the docs:
A good test for this is to put garbage in your .htaccess file and reload the page. If a server error is not generated, then you almost certainly have AllowOverride None in effect.

Requests to /favicon.ico consistently returns the Subversion favicon.ico but I can't find the configuration resulting in this

On one of my servers which is being used for some internal development spaces and the likes, are configured with Apache, Git, Subversion among other things. The VirtualHost configuration is nothing out of the ordinary and I thought I had full control and understanding of this server's configuration and how it runs. I guess I was wrong. I recently discovered that all requests, no matter what VirtualHost I try, return the Subversion favicon when accessing <vhost>.<domain>/favicon.ico. This puzzled me - and annoyed me a bit since I was convinced that I knew all about this server's configuration.
It doesn't seem to pose any problems but I'm annoyed that there is a configuration somewhere which does something I explicitly didn't ask for. So I've been trying to track down this configuration but so far with no luck.
The server is running Gentoo Linux, so I figured I was looking for a <Location> block somewhere in my Apache configuration. I've been going through all my VirtualHost definitions, all my module configurations and my Apache configuration. I've even gone so far as to grep for all <Location> and favicon entries in all of my /etc/ files. Still no luck.
I've run out of ideas as to how I'm going to hunt down this thing so I'm hoping for some help from you guys and girls.
Thank you for your time :)
Okay, I'm a bit wiser. It's a slow day at the office so I have some time to spend on this little detail :)
I now know where the favicon.ico is coming from - I think.
In my server's /var/www/localhost/htdocs/ is a favicon.ico which for some reason unknown to me is the Subversion logo. If I rename this file, all suddenly works and it correctly grabs the favicon I have placed for each VirtualHost.
That's nice but I'm still quite puzzled as to why that hosts favicon took precedence over the individual VirtualHosts favicon. I still can't seem to find any <Location> definitions in any of the VirtualHosts which could lead to this behaviour.

How to set root directory to a subfolder (local php development environment)

I'm just starting to learn web dev, but got myself a bit confused when setting up my local development environment.
I had a php site on shared hosting for some time. I would edit local files and upload them, then refresh to ensure everything worked. A naughty practice I know!
So I have tried to set up a local dev environment and installed AMPPS for a local webserver (PHP5).
I have ambitiously set up the folder structure below so that I can code up a range of websites to try out different languages and frameworks whilst keeping them all seperate. (Square brackets denote folders). Note sure if this is the correct approach... (?)
-->[PHP]
---> [AMPPS]
----> [www]
-----> [PROJECTS]
------> [project_name]
-------> index.php
-------> .htaccess
-------> [images]
-------> [section1]
--------> page1.php
-------> [etc...]
------> [project_name]
------> [project_name]
--> [RUBY]
--> [PYTHON]
My first hurdle however is that all of my links were relative, and I had of course uploaded my site at root with my host. Root in my local dev enironment is now www, which as you can see is several folders up from where I have installed my site.
Links (e.g. Page 1) now display as: "localhost/section1/page1.php" when I believe they should in fact show as "localhost/PROJECTS/project_name/section1/page1.php".
I don't think that telling APACHE that my root directory is [project_name] is the correct approach, because then it wont work for other projects I create. I assume that I should be doing something on a project by project basis to specify it's own root directory.
I thought that I could specify root by adding an .htaccess file to the project_name folder:
From my online research I thought it would go something like:
RewriteEngine on
RewriteRule ^/$ /PROJECTS/project_name/
or perhaps
RewriteEngine on
RewriteRule ^/$ .;C/PHP/AMPSS/www/PROJECTS/project_name/
However I can't get these to work.
When the site was online, I had also coded <?php set_include_path($_SERVER['DOCUMENT_ROOT']); //Look for includes starting from ROOT location ?> at the top every page, thinking I was doing the right thing.
Now I am not so sure that I correctly understood what I was doing there. It doesn't seem to have any impact with or without it in my development environment. And I haven't been able to edit it in any way successfully to resolve my relative links issue.
Sorry for the long post.
I'm grateful for any and all feedback/assistance. Thanks in advance :)
[Resolved] - The advice below was perfect. Thank you all. :)
A tip for Chrome users:
If you are using a custom domain, like I did with .dev, either proceed the address with http://, or end it with a trailing /.
For example I now visit my dev site in Chrome by visiting projectname.dev/ (without the last / it tries to search).
At first I thought I had set up VirtualHost or hosts incorrectly, when in reality it was this Chrome behaviour that that was clouding the issue. At the time of writing, other browsers like Firefox don't share this concern.
Hope that helps someone else out.
You're correct that configuring Apache for each project is the way forward. It's best done with virtual hosts. Define a virtual host for each project and give it a domain name or subdomain for development. In my case I use test.com for all my local development and configure project1.test.com, project2.test.com etc so all my relative paths work as expected. For this I also edit my hosts file so the DNS lookup for test.com and sub projects resolve to my local machine.
Rewriting URLs is something I reserve for a project-by-project basis, without setting global rewrites for a specific server setup. That way my local development environment is close to the actual server environment and project-specific rewrites will work as expected.
Hope that helps
I recommend using method mentioned by #Tak, but I know there might be problems with pre-configured WAMP packs to add virtual hosts, so there is also a solution to use BASE tag in head section of your html:
<base href="http://localhost/PROJECTS/project_name/">