Modifying Apache httpd.conf file via C-Panel - apache

I had my websites set up so that if someone types in a URL with upper case letters and/or underscores, like this - MySite/topics/United_States - it will automatically default to mysite/topics/united-states (lower case and dashes instead of underscores).
I've been through some website crashes, moves and reorganization, and I just discovered this feature is no longer working. I haven't been able to access my online httpd.conf file.
However, I think I discovered a way to do it with C-Panel...
Service Configuration > Apache Configuration > Include Editor > Post VirtualHost Include
"Entering information in this text area will add content to the Apache configuration file (httpd.conf) right after the last VirtualHost entry.
"I wish to edit the Post VirtualHost configuration include file for:"
I selected 2.4.18, and it opens a box where I can type in my code. Above the box it says Filename: post_virtualhost_2.con
And this is the code I want to paste in the box:
RewriteRule (.?[A-Z]+.) /${tolower:$1} [R]
Which brings me to my question. Before I do this I want to make sure I'm not doing something that's going to wreck my site. Does it sound like I'm doing this the right way? And if I somehow mess up this file or paste in the wrong code, how can I fix it?

Have you tried to use this rewrite rule in the .htaccess file of a single cPanel account on the server and test it? It will cause a lot less damage in case it does not work and will be easier to revert (just delete the line).
Please make sure that if you add it in an .htaccess, you also start with:
RewriteEngine On
and then add your rewrite rule.
If you decide to go and edit the global Apache configuration, you should log in the server via SSH and make a copy of the file you are editing:
/usr/local/apache/conf/includes/post_virtualhost_2.conf
If this breaks your site, you can just restore the original file or remove the changes you made and restart Apache, this should fix it.

Related

Apache `host/~username/` opening `/host/directory/`

I have the following:
host/~username/
sends the browser the page /home/username/public_html/index.html. In another directory /home/username/site_root/ we have the root of a website starting with its own /home/username/site_root/index.html.
How to do this: I would like that host/~username/ sends the browser to /home/username/site_root/index.html, if possible keeping host/~username/ as the address in the address bar.
I have never done anything with Apache. Reading some answers it seems that I might be able to do this by adding a file /home/username/public_html/.htaccess with certain commands in it. I have tried imitating what they do with lines like
RewriteEngine on
Rewriterule <...>
but I haven't managed to produce any result.
I tried to avoid using the word redirect because I don't know if that is the name of what I want to do. I don't want it to load some page that then sends the browser to another location.
I saw another thing that is done modifying httpd.conf which changes the root directory of the Apache server. I don't have access to this file.
Have you tried something simpler like a symlink?

Can I in some way include a file with Redirects inside my <VirtualHost>

I migrating a friends webshop from one system to another and trying to make all old urls point to the new ones.
So I got like 10Ks of lines like this:
Rewrite /a /b
I know that I can just add them to inside my <VirtualHost> but it will be hard to read the rest of the <VirtualHost> settings then.
The new webshop is Prestashop and it uses a .htaccess-file and has a <textarea> where you can add extra settings that you want to keep when you regenerate prestashops .htaccess-file.
So I tried to paste all my lines into the <textarea> but it has some kind of limit, so only like half of them where stored.
I can't just paste the lines into .htaccess with a text editor, because sometime you you change som settings in prestashop the .htaccess file needs to be generated and my manually added lines will be overwritten.
So what i'm looking for is a way to include a file with all the Redirects, inside my or in the .htaccess.
Or config apache to load both .htaccess and .htacces2 or something.
Oh it was so easy, just added: Include "file.conf" inside my <VirtualHost> and all works great.

Remove ServerAlias from httpd.conf

I am using WHM/cPanel to manage web hosting and wondering how to remove the "cpanel, whm, webmail" ServerAlias. For example, I DO NOT want anyone to do this {HTTP_HOST}/cpanel in order to get to their cPanel.
These rules are clearly defined in the httd.conf file which is located in
/usr/local/apache/conf
I have already tried to manually modify them and I got the following message:
# DO NOT EDIT. AUTOMATICALLY GENERATED. IF YOU NEED TO MAKE A CHANGE
PLEASE USE THE INCLUDE FILES.
Nothing really happened even though the file was successfully saved. Users are still able to use these unwanted aliases. What should I do to effectively make the change?
Have you restarted Apache?
service httpd graceful
.. or you can do it through WHM.

mod_rewrite - Does Apache caches .htaccess rules? (still follow rules even after deleting the .htaccess file)

I was doing some tests with mod_rewrite in my wamp environment.
I tested a simple rule that I put at the root of one of my websites and asked it to redirect any request ending with index.php to localhost (there is no sense to it, just wanted to check the rule)
It worked, but after, any change I'd made to my .htaccess file rule was not reflected.
After a while I just decided to delete the .htaccess... well it's still doing redirection! I just don't understand it. Does Apache cache the rules or something (restarting services trough wamp menu didn't change anything)
(Don't ask for the exact rule I used, since I deleted the file, I don't think it's relevant anyway)
.htaccess files are processed each time a request comes through. It is possible that your browser cached the request being forwarded. Did you try it with httpfox or anything to see what the headers said?
Have you tried deleting the browser cache?

Popular techniques to debug .htaccess

I'm a self-taught coder and I like to debug by echoing suspicious variables and commenting out code.
Lately, I've had to learn more about the .htaccess file. I need it to do things like interpret php scripts as php5, url rewriting, limit file upload size etc.... I have a lot of trouble debugging a .htaccess file. I often have to migrate PHP applications from one shared hosting environment to another. Sometimes this breaks the .htaccess file (or instead, something in the .htaccess file breaks the site). I check to make sure domain names are updated.
Are there popular techniques for debugging a .htaccess file? Is it just look in the apache logs? Anything else?
Looking in the apache logs is the easiest way to debug .htaccess imho (adding rewriteLog Directive if necessary)
About migrating: if you are not using any physical file paths inside .htaccess (i.e. /var/www/site/script.php) they should be working without problems. If this is not the case, first try to remove all options and leave only redirect directives, in this mode you can see if it's problem with server configuration which denies rewriting of default settings.
Some reference