问题
I'm planning on switching from having my blog on wordpress.com to having it on my own site hosted on my own server. Naturally I want to preserve the link structure from wordpress so that no links to my blog out there on the WWW break.
So my question is, how do I get the following friendly URL
http://example.com/yyyy/mm/dd/post-name
to map to some structure like
http://example.com/index.php?page=bla-bla
on my server using .htaccess?
Can the identifier bla-bla be a simple integer id, or does it have to include both date and name, that would be yyyy-mm-dd-post-name?
Thanks in advance.
EDIT: Thank you for your quick replies. A few additions to my question though: I'm not currently using wordpress.org, so I don't have a control panel that can generate the file for me. At least I think not. And I'm also not going to use wordpress on my own server.
回答1:
You can make following work as you require .. put it in a .htaccess file.
# Options +FollowSymLinks
# RewriteEngine On
#
# RewriteCond %{SCRIPT_FILENAME} !-d
# RewriteCond %{SCRIPT_FILENAME} !-f
#
# RewriteRule ^page/(\d+)*$ ./page.php?id=$1
To read all of the details .. click here to read "friendly and pretty urls"
回答2:
There's a setting on the WordPress control panel that you can activate, and a .htaccess file provided with WordPress that lets it work. It lets you set up the URL's any way you want.
回答3:
WordPress has permalinks built-in and will create an appropriate .htaccess
file for you.
If you're going to use WordPress on your own domain as well, that is.
回答4:
If your host is a Linux server, the rewrite will be supported out of the box. If you host is a Windows server, you will need a rewrite plugin installed.
Windows server is running Helicon Tech ISAPI_Rewrite v3, and it works perfectly fine after I:
Turned the plugin on
In Helm: Home > Domains > domain_name > Website Extensions > URL Rewriting
Wrote my rewrite correctly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /blog/index.php [NC,L]
<blank line>
Changed my WordPress permalinks to custom
/%year%/%monthnum%/%day%/%postname%/
来源:https://stackoverflow.com/questions/1235903/date-and-name-based-friendly-url-using-htaccess