简体   繁体   English

.htaccess 2 index.php上的网址

[英].htaccess 2 urls on index.php

I search alot on google but not get any help. 我在Google上搜索了很多,但没有得到任何帮助。

I have 2 urls like this 我有2个网址

  • domain.com/index.php?page_id=203 domain.com/index.php?page_id=203
  • domain.com/index.php?post_id=12 domain.com/index.php?post_id=12

and i need them like this 我需要他们这样

  • domain.com/203/my-page-name.html domain.com/203/my-page-name.html
  • domain.com/12/my-details-name.html domain.com/12/my-details-name.html

Here my .htaccess file 这是我的.htaccess文件

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?page_id=$1&title=$2 [L]
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?post_id=$1&title=$2 [L]

Above code always open page_id . 上面的代码始终打开page_id Is it possible to make it work or may I make another file for details page? 是否可以使其正常工作,或者我可以为详细信息页面制作另一个文件?

The two rewrite patterns are identical ( ^([^/]*)/([^/]*)\\.html$ ), and Apache has no way of telling the difference between the two. 两种重写模式是相同的( ^([^/]*)/([^/]*)\\.html$ ),Apache无法分辨两者之间的区别。

Consider changing your URI structure to the following: 考虑将您的URI结构更改为以下内容:

  • Pages: /id/name.html , example: /203/page-name.html 页面: /id/name.html ,例如: /203/page-name.html
  • Posts: /posts/id/name.html , example /posts/12/post-name.html 帖子: /posts/id/name.html ,例如/posts/12/post-name.html

As an alternative, you can use one rule to rewrite to, say, index.php?id=$1&title=$2 , eliminating the need for two different query parameters. 或者,您可以使用一条规则来重写为index.php?id=$1&title=$2 ,从而不需要两个不同的查询参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM