-1

ファイルをフォルダなどに保存できるアプリを作っています。

2 つのルールを同じページにリダイレクトできるようにしたいので、.htaccess ファイルに少し問題があります。

私はexample.com/drive自分自身をに書き換えexample.com/drive.phpたいので、この部分は機能しますが、自分example.com/drive/path/to/a/dir/here/自身をに書き換えたいと思っていexample.com/drive?dir=drive/path/to/a/dir/here/ます。

これは .htaccess ファイルで可能ですか? もしそうなら、どのように?

これは私がこれまでに得たコードです:

DirectoryIndex home.php
DirectoryIndex index.php

ErrorDocument 404 /err/404.php
ErrorDocument 500 /err/500.php

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
RewriteRule ^u/(.+)$ /profile.php?u=$1 [L,QSA]
RewriteRule ^f/(.+)$ /file.php?f=$1 [L,QSA]
RewriteRule ^s/(.+)/(.+)$ /page.php?p=$1&f=$2 [L,QSA]
RewriteRule ^s/(.+)$ /page.php?p=$1 [L,QSA]
RewriteRule ^dir/(.+)$ /drive.php?dir=$1 [L,QSA]

このコードは、URL でドライブではなく dir を使用することで機能しますが、それは私が望むものではありません。

前もって感謝します

4

1 に答える 1

1

あなたのルールは正しいでしょう(前述のように変更dirした場合drive)、それらを少し並べ替えるだけです:

DirectoryIndex home.php
DirectoryIndex index.php

ErrorDocument 404 /err/404.php
ErrorDocument 500 /err/500.php

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

# first handle these explicit pattern matches
RewriteRule ^u/(.+)$         /profile.php?u=$1   [L,QSA]
RewriteRule ^f/(.+)$         /file.php?f=$1      [L,QSA]
# it's quite likely this is what you want here instead:
RewriteRule ^s/([^/]+)/(.+)$ /page.php?p=$1&f=$2 [L,QSA]
RewriteRule ^s/(.+)$         /page.php?p=$1      [L,QSA]
RewriteRule ^drive/(.+)$     /drive.php?dir=$1   [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
# I'm guessing you want to only rewrite to script that exists in the root, if
# this is not the case you can change this back to .+
RewriteRule ^[^/]+$ /$0.php [L,QSA]
于 2013-04-08T14:59:57.507 に答える