0

アンダースコアをダッシュ​​で一致/置換する301リダイレクトルールを作成し、末尾の.htmlを削除する必要があります。URLには任意の数のアンダースコアを含めることができます。これが私にとってこれを難しくしています。

PHPでは、次のように実行できます。

$subject = 'this_is_a_bad_url.html';    
$pattern = array('/(_)/', '/.html/');
$replace = array('-', '');
$output = preg_replace($pattern, $replace, $subject);
//$output would result to 'this-is-a-bad-url'

これを.htaccessでどのように書くのですか?

助けてくれてありがとう。

4

1 に答える 1

1

これを試して

  Options +FollowSymLinks -MultiViews
  RewriteEngine on
  RewriteCond %{REQUEST_URI} ^(.*?)_(.*?)$ [NC]
  RewriteRule ^  /%1-%2 [R,L]
  RewriteCond %{REQUEST_URI} ^(.*?).html$ [NC]
  RewriteRule ^  /%1 [R,L]
于 2013-02-15T20:09:54.380 に答える