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

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.

Related

How to avoid displaying directory path in url?

I set up a little Apache2 server on a Raspberry PI4. Now I’m looking for a way to hide the real directory path displayed in the URL. I read around that you should deal with a file called .htaccess but, I don’t even know what to actually look for on the internet. How can I display an arbitrary url in the address bar of the browser, Hiding file extension like .php and file path?
You make rewrite rules in an Apache config file, a .htaccess file for example. One way you could achieve this is to create re-write rules in a .htaccess file. Use to below link to test your rewrite rules, then once you have that part working implement on your live apache installation.
https://htaccess.madewithlove.be/

How to change Apache's hardcoded Error pages?

How to change Apache's hard coded Error pages, instead of using ErrorDocument directive. Because, I do not want to place the ErrorDocument file inside the htdocs folder, as it creates some issues when the user visits the error page itself. Such as the environment variable REDIRECT_URL not working, and stuff like that. I have tried to find stuff in the apache directory, but no luck, i cannot find anything that can be modified to change the hardcoded error pages itself. Is there a way at all to do that?
You can edit them if you install apache from source, download the source from httpd.apache.org/download.cgi, and you can find the contents of the files using grep -rnw '/path/to/somewhere/' -e 'texttofind' if using linux. And modify them to your needs (carefully of course), and you can compile it and use it.
But, I would suggest you to just stick with the ErrorDocument directive, which is much simpler.
Happy Cod3ing.

Modifying Apache httpd.conf file via C-Panel

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.

How Come Everybody Can See My Private Files?

Sorry for the newbie question...
When I go to http://www.plans4boats.com/scripts/youtubeplayer/ in Google Chrome, I can see a full listing of the files there. What should I do if I don't want any old hacker to just come in and view/copy my source codes? Does it have something to do with htaccess?
I discovered that putting a blank index.html file in the folder helps for THAT folder, but it still leaves all subfolders vulnerable.
What should I google for more information on how to set up my server to prevent this?
Just set Options -Indexes for that particular directories either in an .htaccess file or a <Directory> or <Location> container.
What you need to do is turn of Directory Listing for your specific server. I don't know what server you're using so I can't walk you through it, but just google your server name and how to disable directory listing.
I created a file called .htaccess and put the following contents:
IndexIgnore /

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