1

いくつかの変更により、http:http://www.abc.com/asd/ //www.abc.com/asd/zxc/ のような Web ファイルの拡張子をzxc.phpに対して非表示にすることができますが、私がやりたいことは、URL からファイル名を完全に削除することです。ユーザーが Web サイトのどこにアクセスするかは問題ではありませんが、URL は常に静的なままにしておく必要があります。

でそれを行うことは可能.htaccessですか?

私はすでにこれを試しましたが、うまくいきませんでした:

RewriteOptions inherit
RewriteEngine On  # enables url rewriting

RewriteCond %{REQUEST_FILENAME} !-d  # if requested uri is not directory (!-d)
RewriteCond %{REQUEST_FILENAME}\.php -f # and if there is a file named URI+'.php' (-f)
RewriteRule ^(.*)$ $1.php # then if there is any thing in uri then rewrite it as uri+'.php'
4

1 に答える 1

1

よくわかりませんが、提供された URL フラグメントがディレクトリでもファイルでもないので、確認したい問題ではないでしょうか。その場合は.php、フラグメントに追加しますか?

このようなものがうまくいくかもしれません:

RewriteEngine On                    # enable mod_rewrite 
RewriteBase /                       # set the 'base' for the rewrite
                                    # you might need to modify this one.

RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteCond %{REQUEST_FILENAME} !-d # not a directory
RewriteRule ^(.*)$ /$1\.php [L]     # append '.php' to the path
                                    #

次のディレクトリ構造があり、もちろん.htaccess構造のルートにファイルがある場合:

/code/test.php
/index.php

次の URL を使用してtest.phpおよびファイルにアクセスできるはずです。index.php

http://example.com/code/test/

http://example.com/index/

を有効なドメインまたは IP アドレスに変更するexample.com必要があります。

于 2013-10-17T06:53:54.230 に答える