2016-12-21 10 views
1

を変更:プリティURL私は、以下のものを使用してachiveすることができ、かなりurlで変数を渡すしようとしています変数seporator

.htaccessファイル内

domain.com/exercises/lunge+with+dumbells

そして、この:

RewriteEngine On 
RewriteRule ^([a-zA-Z0-9+]+)$ index.php?exercise=$1 
RewriteRule ^([a-zA-Z0-9+]+)/$ index.php?exercise=$1 

は、PHPでアクセスされます:

$urlVars = $_GET["exercise"];

しかし、私はこのように読むために私のURLを必要とする:

domain.com/exercises/lunge-with-dumbells

私はこれが

exercises/?exercise=lunge-with-dumbellsと、このPHP関数を使って仕事を得ることができます:

$urlVars = $_GET["exercise"]; 
$newString = str_replace("-", " ", $urlVars); 

しかし、私は考え可変の文字列を持つかなりのURLのように、+

ではなく、 -で区切られています

多くのありがとうございます。

変更:

答えて

2

あなたの.htaccessは「-」区切りではなく、あなたは自分のPHPファイルに書き換えルールを管理し、正規表現を変更する必要がある「+」セパレーターで清書URLと一致してみましょうするために、

RewriteEngine On 
RewriteRule ^([a-zA-Z0-9+]+)$ index.php?exercise=$1 
RewriteRule ^([a-zA-Z0-9+]+)/$ index.php?exercise=$1 

へ:からルールそれで正規表現を分割する

RewriteEngine On 
RewriteRule ^([a-zA-Z0-9-]+)$ index.php?exercise=$1 
RewriteRule ^([a-zA-Z0-9-]+)/$ index.php?exercise=$1 

は、最も単純なコンポーネントですhttps://httpd.apache.org/docs/current/rewrite/intro.html

:、我々は正規表現と.htaccessの詳細については

^// match the beginning of a strings that start with 
    ( 
    [ // a pattern consisting of 
    a-z //a lowercase alphabet letter 
    A-Z //a uppercase alphabet letter 
    0-9 //a digit 
    - //and the minus sign (here we changed from the + sign to the new value) 
    ] 
    + //one or more occurence of the combination described above 
    ) 

を言うものを作成しようとしているを参照してください。

関連する問題