Can anyone explain the given lines in htaccess file? - .htaccess

In my .htaccess file there are few lines like given below.
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
I want to know do the first two lines and last two lines are doing the same thing? Also want to know can If both are doing the same can i remove the last two lines then?

The correct syntax is "access plus [time]". So the last two lines "do" the same as the first two, although the first two lines aren't formatted correctly.

You can use ExpiresByType directive to add expiration date to cached contents in users browser. For example, when someone tries to get a gif image from your website, the directive below, tells Apache to add Expires header to response,therefore , the browser will cache the file for one year
ExpiresByType image/gif "access plus 1 year"

Related

What is the meaning of a robots.txt that only contains 'User-agent: *'?

I am trying to crawl a website but the robots.txt has just the following line:
User-agent: *
Does it mean that it doesn't care if I crawl their website?
Yes, if User-agent: * is the only line in the robots.txt, you are allowed to crawl everything.
Only Disallow lines have the power to list (beginnings of) URL paths that must not be crawled. If a robots.txt has no Disallow lines, nothing is disallowed.
That said, the author of that robots.txt may have made an error. User-agent lines are typically followed by Disallow lines (or others, like Allow etc.). There is no point in starting a record¹, but not stating anything for the matched user agents.
¹ A record starts with one or multiple User-agent lines, and is separated from other records by a blank line. User-agent: * matches all user agents not matched by any other User-agent line in that robots.txt.

how to rewrite in a htacess file

im into SEO and friendly URL's and im trying to create a rule in my htacess file and i need help...
Basically, i have a list of alphabet letters. If the users selects one letter, the db will show all the lyrics that starts with that letter...
so if i click C, there will be a list of lyrics and the the first is 'Car and blues'
So, from this
htpp://www.website.com/lyrics.php?letter=C
i want to do this:
http://www.website.com/lyrics/C/
so far, this is what i have
RewriteRule ^lyrics/$ /lyrics.php?letter=$1 [L]
the rule should be smart enough to pick everything that comes after 'lyrics', in between the 2 slashes, and not what comes after...
Thanks
the rule should be smart enough to pick everything that comes after 'lyrics', in between the 2 slashes, and not what comes after...
Your rule as it stands is looking for exactly lyrics/ with no possibility of anything before or after it (as defined by the ^ and $).
Assuming you're using letters A-Z in only capitals, you can use this:
RewriteRule ^lyrics/([A-Z])/?$ /lyrics.php?letter=$1 [L]
This will look for a single capital letter after the lyrics/ and send that value to the rewrite URL and also match both cases of having a trailing / or not.
the rule should be smart enough to pick everything that comes after
'lyrics', in between the 2 slashes, and not what comes after...
I'd suggest you look into using regular expressions to format your url. See this link

In J, 1!:2&4 replaces LF with CRLF. Is there a way to keep it as LF?

I have a modified boot.ijs script for J which allows J to respond to a request from Apache.
Essentially, in httpd.conf, I have this:
ScriptAlias /j/ "C:/J/"
DirectoryIndex index.ijs
AddType application/x-httpd-ijs .ijs
Action application/x-httpd-ijs "/j/j.exe"
Which tells Apache to send all *.ijs urls to J. That's just here for the context.
J can then answer by writing to the standard output with:
echo =: 1!:2&4
I have binary data (an Excel file) that I create, then want to send back to the asker's browser, such as detailed here. However, in the file itself, all LF's are changed to CRLF.
This behaviour can be "observed" in jconsole.exe. Type in the declaration for echo above, and send the commands:
echo LF
echo CR
echo LF
You will see that there's one more line after each echo LF, because in the console CR is just written as a single line. In essence, J translates LF to CRLF.
The question: How do you turn it off, make J respect what is actually asked to be outputted?
Learned from their forum that J always outputs as text, never as binary, which means LF is always going to be replaced with CRLF. Huge disappointment.

htaccess redirect/rewrite help

I want to redirect domain.com/1/file.php to domain.com/2/file.php and domain.com/1/pic.jpg to domain.com/2/pic.jpg etc. I want to redirect the subdirectory while leaving to end file in tact. I'm finding it hard to look for a tutorial as I can't describe my problem easily in google. Could someone show me how to do this or direct me to a tutorial about it.
Thanks
RewriteEngine On
RewriteRule ^([0-9])/([a-zA-Z]+).php$ 2/$2.php
Using mod_rewrite...You can do the same thing for your images as well. Essentially the regex expression will collect the value for a backreference. so $1 and $2 since i put 2 regex expressions in there.
Of course, if you need a different match instead of domain.com/1/... you will need to have a regex pattern that matches (but you can just google the appropriate regex expressions you may need but i took your example literally)
Try following for redirect. Replace 1 and 2 with respective subdirectories.
RewriteEngine On
RewriteRule ^1/(.*\.)(jpg|php) /2/$1$2 [L,NC,R=302]

PHP heredoc parse error [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
This produces output page OK
$mystring = "<<<EOT";
Replacing it with the following produces
Parse error: syntax error, unexpected $end in file.php on line 737
$mystring = <<<EOT
This is some PHP text.
It is completely free
I can use "double quotes"
and 'single quotes',
plus $variables too, which will
be properly converted to their values,
you can even type EOT, as long as it
is not alone on a line, like this:
EOT;
Any ideas as to what is causing the parser to choke?
I'm using PHP 4.4.7.
It is only on one file that this behaviour happens all others follow the PHP defined functionality.
What I am trying to recitify is what could be possibly wrong in the proceding lines so that the PHP parser shows in this failure.
John
changed file contents to :-
<?php
$mystring = <<<WHATEVER
This is some PHP text.
WHATEVER;
?>
result =
Parse error: syntax error, unexpected $end in file.php on line 5
Any clues
EDIT
original error was to do with T_ENCAPSED_AND_WHITESPACE this can be caused with jQuery for example "if(x == y){$('#my_image').hide():}" is within the heredoc the bigram "{$ will start the parser looking for php variable for substitution.
EDIT
2 good responses.
1) Ch4m3l3on - "<?php" vs "<?" handling.
2) The Disintegrator - <q>had a similar problem with a stupid program that insisted in putting the BOM in a utf-8 file (ignoring preferences)</q>.
EDIT
1) Replacing all content with a single block didn't fix the problem or give any other pointers.
2) No BOM (Byte Order Mark), pity as this or similar majic characters would have explained all symptoms perfectly.
you have to place your ending heredoc at the beginning of line. if you use some IDE that have indentation, remove them! your ending heredoc must be vertically in the same line as your ending php tag(
Make sure that there is nothing after the 'WHATEVER;'. Even a space will give a parse error.
I would delete the line and retype it, hitting <enter> immediately after typing the semi-colon.
make sure that EOT; is really at the begin of the line.
if ($muh="kuh") {
$foo = <<<EOT
some text text text
EOT;
}
What if you try:
$mystring = <<<'EOT'
...
EOT;
(Notice the single quotes around the first EOT)
I just copy/pasted that into a file and it ran without errors. (PHP 5.2.8 (cli) (built: Feb 6 2009 12:33:08))
So the problem is likely something near that code, but not something you included in the question.
Either that, or a change in PHP since your version was built.
You probably should check if you have any unclosed curly bracket (or brace, can't remember).
For example:
<?php
while(true) {
echo "Something\n";
?>
Will produce that error.
I don't have the rep for an uptic, but Ch4m3l3on and Pedro Cunhna are right... an incorrect heredoc probably won't cause that unexpected $end error, but an unclosed curly brace definitely would.

Resources