Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I would like to redirect http://abc.xyz.ac.uk/folders/abc/lmn http://abc.xyz.ac.uk/folders/abc/lmn.html

Here is the code where I am enabling this

 <Directory /var/www/folders>
            RewriteEngine on
            RewriteRule ^/abc/lmn$ ^/abc/lmn.html [NC,L]
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

What is wrong with this rule and is this the correct place to include rewrites?

Thanks

share|improve this question
    
Why have you determined it's 'wrong'? Are you seeing errors in your logs? Is it just not working? What troubleshooting steps have you taken so far? –  yoonix Jun 21 '13 at 21:55
    
One thing is that I cannot get access to the logs on the Ubuntu server I am using, I did do a tail of the access log, but there are no rewrite errors and the rewrite is not firing. –  user10211 Jun 21 '13 at 22:26
    
@user10211 Do you want to redirect so that the client has the .html in their address bar, or do you just want to display the content from the .html file without sending the client a redirect? –  Shane Madden Jun 22 '13 at 6:57
add comment

3 Answers

Rewrite paths work differently inside a <Directory > context. The path you are matching is the full filesystem path with the current directory (including the trailing slash) removed.

The effect of this is that you need to remove the leading slash from your regex and the replacement or move the rewrite rule outside the directory context where it will be matching the URI instead of a filesystem path.

Note that a .htaccess file is implicitly in a directory context because it is in a directory.

You also shouldn't have a caret in the replacement. The second argument is not a regex.

You mentioned a redirect in your question. To make that happen you need [R] or one of the more specific codes ([R=301] or [R=303]) after the second argument.

share|improve this answer
add comment

Try this instead:

RewriteRule ^/abc/lmn$ /abc/lmn.html [NC,L]

As per https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule, the arguments to RewriteRule are a pattern, a substitution, and some flags. The ^ character will be treated as a literal in the substitution part, which is probably not what you want.

mod_rewrite has excellent logging, which can be helpful for debugging this sort of problem. Enable it with LogLevel alert rewrite:trace3, and tweak the level anywhere up to trace8 to get the level of detail you need. More details on the logging here:

https://httpd.apache.org/docs/current/mod/mod_rewrite.html#logging

share|improve this answer
    
I am afraid your suggestion did not work. I did set the loglevel to alert and setup my own logs, but there is nothing in there. –  user10211 Jun 21 '13 at 22:37
add comment

Try the following:

<Directory /var/www/folders>
        RewriteEngine on
        RewriteBase /folders
        RewriteRule ^/abc/lmn$ /abc/lmn.html [NC,L]
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
</Directory>
share|improve this answer
    
I have tried all the above suggestions. This is how the final looks like and unfortunately it does not work code Document root /var/www/folders <Directory /var/www/folders> RewriteEngine on RewriteBase /folders RewriteRule ^/abc/lmn$ /abc/lmn.html [NC,L] Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> –  user10211 Jun 21 '13 at 23:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.