mod_rewrite all robots.txt requests to default file, server-wide - .htaccess

So, I have a development server running OpenSuse with apache. There are loads of projects on this server, some of them have an online/live counterpart.
Each project has a separate subdomain.
How do I rewrite all requests for robots.txt to one "default"-file, server wide?
My goal is to prevent indexing from search-bots.

I believe there is no easier way than to set an Alias in every VirtualHost directive:
Alias /robots.txt /home/path/to/generic/robots.txt
I'm happy to stand corrected by a truly global solution, though.

I was having the same problem and found that I could place the Alias declaration that Pekka suggests in the httpd.conf outside of the VirutalHost directive and it applied to all sites.

Related

How do I make apache2.4 configuration specific to a particular virtualhost so it doesn't affect other virtualhost on a centos server

I have put in my include file which is in this directory /etc/apache2/conf.d/userdata/std/2_4/myusername/sub.domain.com/proxy.conf.
On the file I did proxy reverse to localhost port 5000 for my net core app.
Then I did a post virtualhost include using include editor.
When I try to reach other domain on same VPS I get server temporarily unavailable to handle request error.but when I uncommented the proxy reverse on my include file i was able to reach other domain.
So my question is given the procedure I have taken, why is an include specified for a particular virtualhost affecting other virtualhosts on the server.
Proxy reverse code in the include file is code below
ProxyPass / http://127.0.0.1:5000/
ProxyPassReverse / http://127.0.0.1:5000/ ```
And this include was applied to virtualhost for the particular sub domain, don't know why it affects other virtualhosts.
Then I did a post virtualhost include using include editor.
If this means outside the <virtualhost> then its no wonder it affects all virtualhosts -- outside of <virtualhost> is global.
what i did was i opened up the post_virtualhost_global.conf file found in /etc/apache2/includes/.
then i removed the include statement from the post_virtualhost_global.conf file, then it worked, i dont seem to understand how, but it worked perfectly anyway. i have also applied same practice for subsequent virtualhost proxyreverse includes i have done afterward.

How to implement leverage browser caching in nginx?

I have ho access to nginx.conf file (I see it but have no permission to edit it). Trying to add directive for mod_headers in .htaccess - no result. That is interesting, because mod_rewrite works fine through .htaccess
You have to add it to the nginx config, for the location in question to add or change any headers. Unless you can get access to config and reload config, you can't do it yourself.

Configure httpd.conf to add new site on Apache Red Hat Linux

I have linux server (Red Hat Enterprise Linux Server release 5.3 (Tikanga)) with apache installed. It is already used for browsing some documents. Now I would like to add a new Directory (with a html page), so whenever the directory is browsed it can display the html page.
But I am not sure of where all to edit the httpd.conf file
Existing httpd.conf:
When I hit the url "http://servername/eng" it displays list of folders.
Now, I want to add a website to this existing, so when user hit the url "http://servername/builds" it should display a html page in the browser.I have added my "index.html" page in location "/var/www/html/builds/"
For this I added the below code to httpd.conf file
Please let me know what all modifications are required in the conf file
You can do it in a few different ways.
Putting index.html in /build
This requires you to have this setting:
DirectoryIndex index.html
(it should be there by default on most platform.)
Also for this to work, rather than putting new <Directory>, you should put the build/ directory in the directory that holds your http://example.com/ files. For instance:
/var/www/example.com/public_html/eng/
/var/www/example.com/public_html/builds/
/var/www/example.com/public_html/builds/index.html
Storing build/ in folder completely unrelated to example.com, but still be able to reach it via example.com/builds
For this, you need to rewrite the URLs so that example.com/builds redirects the user to the final URL. This is most easily achieved through mod_rewrite. You enable mod_rewrite module in your Apache's configuration, make sure that example.com can have .htaccess files through ensuring proper AllowOverride entry in example.com's <Directory> configuration, create /var/www//example.com/public_html/.htaccess (or similar) file, and fill it RewriteEngine On and RewriteRules you need. More on mod_rewrite in the Internet and in the documentation.
Completely separate virtual server, for example builds.example.com/
In this case, what you're looking for are virtual servers. These are not defined in httpd.conf or configuration itself, but usually have dedicated directory.
For example, to add builds.example.com that works for port 80, you'd need to create following entry:
<VirtualHost *:80>
ServerName builds.example.com
DocumentRoot /var/www/builds.example.com/public_html/
</VirtualHost>
Where to put this? Well, it depends on the platform. For Debian, you put this in a new file in /etc/apache2/sites-available/, e.g. /etc/apache2/sites-available/example.com, and symlink to it in /etc/apache2/sites-available (on Debian, you can do this easily with a2ensite <NAME_OF_FILE>. On your platform this procedure might be different, so look it up ("adding virtual servers on " would be a start). After adding virtual servers, you need to reload your Apache configuration.
Please let me know if this satisfies your question, if not, I'll edit the answer accordingly.

Configure PhpStorm to use .htaccess

I added .htaccess (for rewriting URLs) in my project's root directory but it's not working. I checked twice, the same file is working fine in Eclipse.
How do I configure PhpStorm to use .htaccess?
Indeed, PHP's built-in web server will never fully support .htaccess features. Note: it is PHP's, it is NOT PHPStorm's built-in server.
But there is a way around.
Most of the time, rewrites are needed only to redirect all the nonstatic file queries to index.php. If you only need this, you can set the server's "router script" in PHPStorm run configuration to index.php.
After that, a modest hack in index.php to serve static files from the drive may speed things up.
Add to the very beginning of index.php:
if (preg_match('/\.(?:php|png|jpg|jpeg|gif|ico|css|js)\??.*$/',
$_SERVER["REQUEST_URI"]))
{
return false; // serve the requested resource as-is.
}
Do you use the same server/configuration when working with PhpStorm and Eclipse?
As it was explained in the comments, it has nothing to do with the IDE, but with the web server (Apache) and its configuration.
You can edit .htaccess with any editor, if this virtualhost/directory configuration has AllowOverride All, ModRewrite is enabled and your rewrite rules are correct, it will work just fine.
You need to ensure that your PHP files are served from the correctly configured web server.

Joomla SEF Apache mod_rewrite not working on new hosting setup, possible RewriteBase rule?

I recently moved my sub-domain hosted Joomla (sub.domain.com) to another host and my SEF URL's are broken. Currently I have Apache mod_rewrite turned off in the Joomla admin forcing the /index.php/ within all URL's
Apache mod_rewrite is loaded and working correctly. The major different in my hosting setup is that before my VPS host had a directory for the sub-domain within the server structure /home/me/sub.domain.com/ now it seems the new host is using another rewrite? as the server files is located in /var/www/domain.com whereas the front-end browser points to http://sub.domain.com
Not sure if there is a custom RewriteBase rule I'm not familiar with to correct this or perhaps there is another rewrite going on within the hosting which I'm not aware of?
Thanks for you time.
Have you made sure, that you DO NOT have set AllowOverride in your vhosts file to "none" ?

Resources