More .htaccess help


#1

I can’t seem to create a .htaccess file that doesn’t result in a 500 error. I have uploaded it using ASCII mode. I set the permissions to 644 - and I have the following line in the file:

redirect /home/user/domain.com/file.html
http://www.domainc.com/anotherfile.html

What am I doing wrong? Is my syntax wrong? Am I not pointing to the user directory correctly?

Do I need this at the beginning of the file?

File: /home/user/domain.com/.htaccess

Nothings seems to work.


#2

Syntax is your problem. What are you trying to do? Create a redirect rule based on going to a select page?

Try this:

RewriteEngine On
RewriteRule ^file.html$ http://www.domainc.com/anaotherfile.html [R]


#3

So - I need all of that in the .htaccess file?

Sorry - tres new on this one.

what is: ^file.html

Do I need the full path to the user account? Or does that not matter?

RewriteEngine On
RewriteRule ^file.html$ http://www.domainc.com/anaotherfile.html [R]


#4

^file.html$ is pattern matching; Starts with ‘f’ and ends with ‘l’ with the letters in between being in that order.

You could get away with file.html, too.

And yes, you need both them lines. You gotta first tell Apache you’re turning on the RewriteEngine and then you supply your rules.


#5

Redirect uses URI paths, not filesystem paths. That is, all paths should be relative to the root of the web site. The following is the correct syntax:

Redirect /file.html http://www.domainc.com/anotherfile.html Don’t incur the overhead of mod_rewrite unless you actually need it (you don’t).


If you want useful replies, ask smart questions.


#6

Thanks so much. I’m going to try this in the morning - I’ll let you know how it goes.


#7

The first one - in the root of the web server is working - meaning the first redirect.

How do I tell the .htaccess to go one directory down and redirect in the same file?

RewriteEngine On
RewriteRule ^rss.xml$ http://feeds.feedburner.com/jaybrewernet [R]
RewriteRule ^/fastfoodfever/rss.xml$ http://feeds.feedburner.com/FastFoodFever-FastFoodNewsCrazyFastFoodCreations [R]

The second fast food fever one is not working.


#8

In .htaccess files, the per-directory prefix is removed when the pattern is matched for the RewriteRule directive. This means:

RewriteRule ^/fastfoodfever/rss.xml$ http://feeds.feedburner.com/FastFoodFever-FastFoodNewsCrazyFastFoodCreations [R]is incorrect because you have a slash that should not be there. It should be:

RewriteRule ^fastfoodfever/rss.xml$ http://feeds.feedburner.com/FastFoodFever-FastFoodNewsCrazyFastFoodCreations [R]In other words,

Given /path/.htaccess, the prefix is /path/

Step 1. Remove prefix
/path/fastfoodfever/rss.xml -> fastfoodfever/rss.xml
Step 2. Match pattern
^fastfoodfever/rss.xml$ matches fastfoodfever/rss.xml

Aslo, technically the pattern should be ^fastfoodfever/rss.xml$ - note that the period in a pattern has a special meaning; it matches “any character”. If you don’t put a backslash in front of the period, then a URL like this:
http://example.com/rssTxml
would still cause the redirect, because the period would match the T.

Also, using the RewriteEngine for this situation is overkill. You can do the same thing with

Redirect /rss.xml http://feeds.feedburner.com/jaybrewernet Redirect /fastfoodfever/rss.xml http://feeds.feedburner.com/FastFoodFever-FastFoodNewsCrazyFastFoodCreationsGiven that you don’t need pattern matching and conditions.

:cool: Perl / MySQL / HTML+CSS