如何更改http:mydomainname.com/inner-page.php条款ArticleID = 10到http:mydomainname.com/inner-page.php/Title如

2023-09-02 20:32:35 作者:窒息的感觉

如何更改http:mydomainname.com/inner-page.php条款ArticleID = 10到http:??mydomainname.com/inner-page.php条款ArticleID =标题  请给我一个简单的方法我也尝试URL重写。

how to change http:mydomainname.com/inner-page.php?articleid=10 To http:mydomainname.com/inner-page.php?articleid=Title please give me a easy way i have also tried Apache mod_rewrite.

但我的困惑是,如何.htaccess文件知道我的称号ID

but my confusion is that how to .htaccess file know my title by id

推荐答案

您不能用的mod_rewrite或Apache独自做到这一点,因为没有办法Apache或mod_rewrite的知道如何从10翻译标题。你很可能需要与数据库进行查找做到这一点,你最好在你的这样内page.php

You cannot do this with mod_rewrite or Apache alone, because there is no way Apache or mod_rewrite know how to translate from "10" to "Title". You'll most likely want to do this with a database lookup, and you are better off doing this in your inner-page.php.

if( isset( $_GET['articleid'] ) ) {
  $title = database_lookup_function( $_GET['articleid'] );
  header( '302 Moved Temporarily' );
  header( "location: /inner-page.php?articletitle=$title" );
  exit();
}

或者,如果你真的想保持相同的变量彻底你的整个脚本,这听起来很傻:

Or if you really want to keep the same variable thorough your entire script, which sounds silly:

if( isset( $_GET['articleid'] ) && intval( $_GET['articleid'], 10 ) == $_GET['articleid'] ) {
  $title = database_lookup_function( $_GET['articleid'] );
  header( '302 Moved Temporarily' );
  header( "location: /inner-page.php?articleid=$title" );
  exit();
}

要加载inner-page.php?category=radiono&lanug=India&articleid=sarukh-khan-performs-a-na‌​tural-language当内page.php / radiono /印度/ sarukh汗 - 执行 - 一个自然语言要求,使用以下规则:

To load inner-page.php?category=radiono&lanug=India&articleid=sarukh-khan-performs-a-na‌​tural-language when inner-page.php/radiono/India/sarukh-khan-performs-a-natural-language is requested, use the following rule:

RewriteRule ^inner-page.php/([^/]+)/([^/]+)/([^/]+)/?$ /inner-page.php?category=$1&lanug=$2&articleid=$3 [L]