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.

My old site was dynamic so all the permalinks were of this form:
http://wangling.me/2000/01/file or `http://wangling.me/2000/01/file/

Now I just rebuilt my site with static html files so permalinks become:
http://wangling.me/2000/01/file.html

So I want to map old permalinks to new permalinks. I wrote this in /etc/apache2/sites-enabled/wangling.me:

<VirtualHost *:80>
     ServerAdmin xxx
     ServerName wangling.me
     ServerAlias *.wangling.me
     DocumentRoot doc_root
     RewriteEngine On
     RewriteCond /$1 !-d
     RewriteCond /$1 !-f
     RewriteCond /$1.html -f
     RewriteRule ^/([^.]+?)/*$ /$1.html
</VirtualHost>

But it does not work. Here are the relevant logs:

[Sat Jan 19 00:49:01 2013] [error] [client 24.12.163.253] File does not exist: doc_root/2012/05/xyz

So it seems the RewriteRule is not used. I know there must be something wrong with my config because I'm even not sure what exactly Pattern is in RewriteRule Pattern Substitution. Is it the absolute URL(http://wangling.me/2012/05/xyz), relative URL(2012/05/xyz), absolute file path(doc_root/2012/05/xyz), or relative file path(2012/05/xyz)?

share|improve this question
    
use RewriteLog to troubleshoot. If your rules are alright, look at your error_log more closely. Perhaps something like SELinux is to blame. –  fuero Jan 19 '13 at 16:21
    
Can you clarify your new document path. Did you not rename the files .html? If you did, then RewriteCond /$1 !-d may be the issue since the directory now exists. –  jeffatrackaid Jan 22 '13 at 16:06
    
@jeffatrackaid You can think of it as renaming from file to file.html. Why would /$1 exist? Isn't $1 = file? –  an0 Jan 22 '13 at 16:25

1 Answer 1

up vote 0 down vote accepted

By try-and-error, I found that Pattern is relative URL(/2012/05/xyz) in RewriteRule Pattern Substitution. So the correct configure is:

<VirtualHost *:80>
     ServerAdmin xxx
     ServerName wangling.me
     ServerAlias *.wangling.me
     DocumentRoot doc_root
     RewriteEngine On
     RewriteCond %{DOCUMENT_ROOT}/$1 !-d
     RewriteCond %{DOCUMENT_ROOT}/$1 !-f
     RewriteCond %{DOCUMENT_ROOT}/$1.html -f
     RewriteRule ^/([^.]+?)/*$ /$1.html
</VirtualHost>
share|improve this answer

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.