Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have wrote this lines in my .htaccess file:
<Directory /img>
Header set Cache-Control "max-age=604800, public"
</Directory>
But the server encountered an 500 Internal Server Error.
I really want to apply that rule to few directories (like: img/ js/ icons/ ),
but not to all of the image files in the site.
The question:
What is the right way to apply a rule to whole directory ?
Is it possible by single htacess file, without htacess file in each directory ?
You can't use a <Directory> block inside an htaccess file (which is essentially a <directory> itself). If you want to have requests for /img set a cache-control header, then put:
Header set Cache-Control "max-age=604800, public"
in the htaccess file in the /img directory.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Like the title says I want to visit my webpage without typing .html after the webadres.
So for example I have to type this at the moment: www.webadres.com/webpage.html
Now I want to change that into www.webadres.com/webpage
I've already tried some things like deleting the .html extension on the end of my file but that (of course) doesn't work.
I see I missed something:
I don't really understand it but I got a folder (called "cgi-bin") with a .htacces file.
In the .htacces file is the following text:
Options -Indexes +ExecCGI AddHandler cgi-script .cgi .pl
I want a webpage like this
www.example.com/webpage
Instead of
www.example.com/webpage.html
I didn't know about all the server side technologies but now it seems I have Apache.
If it didn't worked out you could also check out these:
How to remove .html from URL
ReWrite rule to add .html extension
create a htaccess file which has the name of .htaccess, then place the following code
RewriteEngine on
RewriteRule ^yourPage$ yourPage.html [NC,L]
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have a website saying :
http://domain.com/
mirror site on
http://cdn.domain.com/
I don't want cdn to be indexed. How can I write robots.txt rule to avoid the cdn from being indexed without disturbing my present robots.txt excludes.
My present robots.txt excludes :
User-agent: *
Disallow: /abc.php
How can I avoid cdn.domain.com from being indexed ?
User-agent: *
Disallow: /abc.php
in your root .htaccess file add the following
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^Amazon.CloudFront$
RewriteRule ^robots\.txt$ robots-cdn.txt
And then create a separate robots-cdn.txt:
User-agent: *
Disallow: /
When accessed through via http://cdn.domain.com/robots.txt will return the contents of the robots-cdn.txt file... otherwise the rewrite won't kick in and the true robots.txt will kick in.
This way you are free to mirror the entire site (including the .htaccess) file with the expected behavior
Update :
HTTP_USER_AGENT did it since Amazon uses it while querying it from any location.
I have verified and it works
If the codebase are the same, you can generate your robots.txt dynamically and change its content depending on the requested (sub)domain.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Adding this to an older system and am trying to do it in the .htaccess file.
# Prevent search engine indexing on dev sites:
SetEnvIf Host myliveserver\.com$ isproduction
Header set X-Robots-Tag "noindex, nofollow, noarchive" env!=isproduction
Running on Apache 2.2.22 with mod_setenvif
Getting a dreaded 500.
If I remove the conditional env!=isproduction it runs.
What am I missing about the conditional clause?
There are two possibilities for a 500 status code
mod_header isn't enabled
according to Header
Syntax: Header [condition] set|append|merge|add|unset|echo|edit header [value] [replacement] [early|env=[!]variable]
...
env=[!]varname
The directive is applied if and only if the environment variable varname exists. A ! in front of varname reverses the test, so the directive applies only if varname is unset.
So, your header directive should be
Header set ... env=!isproduction
Ah.. there it is...
=! vs !=
The NOT is applied to the variable, not the equality.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
as of title, I'm having problems with my .htaccess file, everything should be set fine, but has I write something as basic as
RewriteEngine on
it starts giving me that nice 500 Internal Server Error. I'm hosting on localhost on an Apache server (UNIX)
Obviously I triple checked that everything is set fine, and top of all that mod_rewrite is loaded.
Thanks for your precious help!
If the error occurs for every single type of instruction you put in the file (that is, caching, FilesMatch, ErrorDocument, etc), there are two possible options that I can think of right now:
The encoding of your .htaccess file is not compatible with the server you're running. Try converting it to ANSI, and then try again (Apache does not support Byte Order Marks, so you'd need to save it to ANSI, or UTF-8, without the BOM). If that does not work:
AllowOverride is not set correctly, or not at all. If you have access to the Virtual Host/Directory configuration, you'll need to enable it by adding the line AllowOverride All in the <Directory> container.
When you try to remove the code RewriteEngine on and the URL remapping or the URL redirecting is still functioning well, then you do not have to put that code in your .htaccess file, for your HTTP server was already configured that the rewrite engine is on. But if you've tried to remove it and the rewriting or the redirecting stop, then you must include all your .htaccess codes in your question. Then if it's empty, then why you need to turn the RewriteEngine on if you're not going to apply even a single RewriteRule?
Have you ever tried this:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^notexist.html$ /index.html
And try to visit yourdomain.com/notexist.html if it's URL remapping into /index.html.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have many url links in /abc/ sub-directory, like
http://www.domain.com/abc/products-12345
http://www.domain.com/abc/products-23456
http://www.domain.com/abc/products-34567
http://www.domain.com/abc/new-items
Now I want to url rewrite /abc/products- to /def/products-
http://www.domain.com/def/products-12345
http://www.domain.com/def/products-23456
http://www.domain.com/def/products-34567
http://www.domain.com/abc/new-items
My code in .htaccess, but nothing changed. How to rewrite in this case? Thanks.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^abc/products-(.*)$ /def/products-$1 [L,R=301]
</IfModule>
As you can test on this simulator the rules should work.
The most probable problem you are facing should be:
The global configuration does not allow for .htaccess overwrite
.htaccess is not readable for apache user
You have no mod_rewrite active on this apache server, thus no trigger to <IfModule> directive.
Best troubleshooting option would be trying a redirection of all page to a static page. If this does not work, look for a configuration problem.