3

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)?

3
  • 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. 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
0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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