2017-11-21 18 views
0
私が探している

から、.htaccessファイルに二つの変数にURLを変更するには、次.htaccessの書き換えルール、変更URL

domain.com/folder/a123/url/index.php 
domain.com/otherfolder/a321/url/index.php 

へ:

domain.com/folder/url/index.php 
domain.com/otherfolder/url/index.php 

私は希望可能であれば、1行で.htaccess RewriteRuleを使用してください。

「フォルダ」と「その他のフォルダ」は「フォルダ名」の2つだけで、「a123」/「a321」は「a」で始まり、乱数で終わるものです。

答えて

0

あなたはこれを使用してちょうど1ルール1であることを行うことができます。

RewriteEngine on 
RewriteRule ^(.+)/a[0-9]*/url/index.php$ /$1/url/index.php [R=301,NC] 

しかし、あなたはすべてのページだけでなく、index.phpをリダイレクトしたい場合は、この使用します。場合は、また

RewriteRule ^(.+)/a[0-9]*/url/(.*)$ /$1/url/$2 [R=301,NC] 

をリダイレクトする代わりにURLを書き換えたい[R=301,NC][NC]に変更します。

このパターンが他のURLにもある場合は、このルールも適用されます。たとえば、domain.com/adifferentfolder/a567/url/index.phpdomain.com/adifferentfolder/url/index.phpにリダイレクトされます。これらのタイプのURLがあり、リダイレクトしたくない場合は2つのルール代わりに:

RewriteRule ^folder/a[0-9]*/url/(.*)$ /folder/url/$1 [R=301,NC] 
RewriteRule ^otherfolder/a[0-9]*/url/(.*)$ /otherfolder/url/$1 [R=301,NC]