使用 .htaccess 基于日期和名称的友好 URL

发布于 2024-07-30 10:38:58 字数 542 浏览 8 评论 0原文

我计划将我的博客从 wordpress.com 上切换到在我自己的服务器上托管的我自己的网站上。 当然,我想保留 WordPress 的链接结构,这样 WWW 上指向我博客的链接就不会中断。

所以我的问题是,如何使用 .htaccess 获取以下友好 URL

http://example.com/yyyy/mm/dd/post-name

来映射到某些结构,例如

http://example.com/index.php?page=bla-bla

我的服务器上的结构?

标识符 bla-bla 可以是一个简单的整数 id,还是必须同时包含日期和名称,即 yyyy-mm-dd-post-name?

提前致谢。


编辑:感谢您的快速回复。 不过,对我的问题进行一些补充:我目前没有使用 wordpress.org,因此我没有可以为我生成文件的控制面板。 至少我认为不是。 而且我也不打算在我自己的服务器上使用 WordPress。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

吝吻 2024-08-06 10:38:59

您可以激活 WordPress 控制面板上的一个设置,以及 WordPress 附带的 .htaccess 文件,使其可以正常工作。 它允许您以任何您想要的方式设置 URL。

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.

油饼 2024-08-06 10:38:59

WordPress 具有内置的永久链接,并将为您创建适当的 .htaccess 文件。
如果您也打算在自己的域上使用 WordPress,那就是了。

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.

◇流星雨 2024-08-06 10:38:59

如果您的主机是 Linux 服务器,则将立即支持重写。 如果您的主机是 Windows 服务器,则需要安装重写插件。

Windows 服务器正在运行 Helicon Tech ISAPI_Rewrite v3,并且在我执行以下操作后,它工作得非常好:

打开插件

In Helm: Home > Domains >  domain_name > Website Extensions > URL Rewriting

正确编写我的重写

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /blog/index.php [NC,L]
<blank line>

将我的 WordPress 永久链接更改为自定义

/%year%/%monthnum%/%day%/%postname%/

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%/
如梦 2024-08-06 10:38:58

您可以根据需要进行以下工作..将其放入 .htaccess 文件中。

# Options +FollowSymLinks  
# RewriteEngine On  
#   
# RewriteCond %{SCRIPT_FILENAME} !-d  
# RewriteCond %{SCRIPT_FILENAME} !-f  
#   
# RewriteRule ^page/(\d+)*$ ./page.php?id=$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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文