mod_rewrite: nasıl farklı bir dosyaya işaret ancak sorgu vars tutmak için?

2 Cevap php

Ben iyi çalışan bu rewriteRules var:

# 4 params
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?app=$1&do=$2&what=$3&id=$4 [NC,L,QSA]

# 3 params
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?app=$1&do=$2&what=$3 [NC,L,QSA]

# 2 params
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?app=$1&do=$2 [NC,L,QSA]

# 1 param
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?app=$1 [NC,L,QSA]

Now, i would like that if the url contains /api/ then i would like it to point to a file called public.api.php but still have those 4 query vars as parameters. I could arrange that via explicitating all the rules in the order in which they should be processed, but it makes for a quite lengthy .htaccess file.

Benim soru şudur: /api/ istenen URI olduğunu ve index.php veya {[bu, noktaya göre (eğer kontrol istiyorsunuz koşullu kural çeşit eklemek için bir yol var 2)]} dört sorgu vars işlenmesini yinelenen olmadan?

2 Cevap

Sadece bazı kuralları gibi eklerseniz kolay olacaktır:

RewriteRule ^api/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ public.api.php?app=$1&do=$2&what=$3&id=$4 [NC,L,QSA]
RewriteRule ^api/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ public.api.php?app=$1&do=$2&what=$3 [NC,L,QSA]
RewriteRule ^api/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ public.api.php?app=$1&do=$2 [NC,L,QSA]
RewriteRule ^api/([A-Za-z0-9-]+)/?$ public.api.php?app=$1 [NC,L,QSA]

Edit İşte bir yaklaşım:

RewriteRule (^|.+?/)api/?([^/].*)?$ $1$2

RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?app=$1&do=$2&what=$3&id=$4 [NC,L,QSA]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?app=$1&do=$2&what=$3 [NC,L,QSA]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?app=$1&do=$2 [NC,L,QSA]
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?app=$1 [NC,L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^?\ ]+/)?api/?
RewriteRule ^index\.php$ public.api.php [L]

Sadece kaçmak? ve bir grup olarak tüm params'ı ele?

RewriteRule ^.*/api/.*\?(.*)$ /public.api.php?$1 [NC,L,QSA]