0

私はこの.htaccess行を持っています:

RewriteRule ^forum_(.*).html forum.php?frm=$1 [L]

そして私はこのphp行を持っています:

$url = str_ireplace('forum.php?frm=', 'forum_.html', $url);

しかし、URLは次のようになります。

forum_.html1

そして私はURLを次のようにしたいと思います:

forum_1.html

どうやってするか??

完全な.htaccessファイル:

    RewriteEngine On
# begin index Page Rewriting
RewriteRule ^index index.php [L]
RewriteRule ^index.html index.php [L]
RewriteRule ^index.htm index.php [L]
RewriteRule ^forum_(.*)\.html forum.php?frm=$1 [L]
RewriteRule ^topics_(.*) thread.php?tpc=$1 [L]
RewriteRule ^tpcs_auth_(.*) tpcs.php?auth=$1 [L]
RewriteRule ^tpcs_rauth_(.*) tpcs.php?rauth=$1 [L]
RewriteRule ^users_(.*) user.php?id=$1 [L]
RewriteRule ^chat.html chat.php [L]
RewriteRule ^signup.html signup.php [L]
RewriteRule ^users.html users.php [L]
RewriteRule ^cp.html Upanel.php [L]
RewriteRule ^messages.html pm.php [L]
RewriteRule ^style=(.*) changetemplate.php?action=changestl&styleid=$1 [L]
RewriteRule ^lostpw.html lostpw.php [L]

# end

完全なseo.phpファイル:

    $seotp = $config->Cquery("site_seo");
if($seotp == 0)ob_start();

function change_links(){
global $seotp;
if($seotp == 0){
$contents = ob_get_contents();
$contents = rewrite($contents);
ob_end_clean();
echo $contents;
}
}

function rewrite($url){
global $seotp;
if($seotp == 0){
$url = str_ireplace('href="index.php', 'href="index.html', $url);
$url = str_ireplace('href="./index.php', 'href="./index.html', $url);
$url = str_ireplace('href="./forum.php?frm=', 'href="./forum_.html', $url);
$url = str_ireplace('forum.php?frm=', 'forum_.html', $url);
$url = str_ireplace('href="./thread.php?tpc=', 'href="./topics_', $url);
$url = str_ireplace('thread.php?tpc=', 'topics_', $url);
$url = str_ireplace('href="./user.php?id=', 'href="./users_', $url);
$url = str_ireplace('user.php?id=', 'users_', $url);
$url = str_ireplace('tpcs.php?auth=', 'tpcs_auth_', $url);
$url = str_ireplace('tpcs.php?rauth=', 'tpcs_rauth_', $url);
$url = str_ireplace('href="./tpcs.php?auth=', 'href="./tpcs_auth_', $url);
$url = str_ireplace('href="./tpcs.php?rauth=', 'href="./tpcs_rauth_', $url);
$url = str_ireplace('href="chat.php', 'href="chat.html', $url);
$url = str_ireplace('href="users.php', 'href="users.html', $url);
$url = str_ireplace('href="./users.php', 'href="./users.html', $url);
$url = str_ireplace('href="singup.php', 'href=".singup.html', $url);
$url = str_ireplace('href="./singup.php', 'href="./singup.html', $url);
$url = str_ireplace('href="./Upanel.php', 'href="./cp.html', $url);
$url = str_ireplace('href="Upanel.php', 'href="cp.html', $url);
$url = str_ireplace('href="./pm.php', 'href="./messages.html', $url);
$url = str_ireplace('href="pm.php', 'href="messages.html', $url);
$url = str_ireplace('href="./lostpw.php', 'href="./lostpw.html', $url);
$url = str_ireplace('href="lostpw.php', 'href="lostpw.html', $url);
$url = str_ireplace('href="./changetemplate.php?action=changestl&styleid=', 'href="./style=', $url);
$url = str_ireplace('href="changetemplate.php?action=changestl&styleid=', 'href="style=', $url);
return $url;
}
}

関数を呼び出すとき:change_links();

4

1 に答える 1

1

preg_replace を使用する必要があります。

$url = preg_replace('/forum.php\?frm=([0-9]+)/', 'forum_$1.html', $url);

正規表現を使用すると、問題が解決します。

于 2013-01-26T12:53:02.877 に答える