0

バニティURLが必要な次のページがあるサイトを構築しようとしています。

  • account.php
  • 質問.php
  • profile.php

表示する必要があります

www.mysite.com/account?req=settings
www.mysite.com/account?req=questions
www.mysite.com/account?req=answers

次のように

www.mysite.com/account/settings
www.mysite.com/account/questions
www.mysite.com/account/answers

そして、他のファイルについては、次のものが必要です。

など:-www.mysite.com/questions?id=0484684

として

www.mysite.com/questions/0484684

www.mysite.com/profile?id=123456

なので

www.mysite.com/profile/123456

私は本当にこれを可能にする必要があるので、誰かが私を助けてくれますか?

URLから.php拡張子も削除したいと思います。

私はhtaccessファイルの経験がないと言いたいです。

助けてくれてありがとう、それはうまくいきました!!!

4

2 に答える 2

4

.htaccessファイルに次のルールを追加します。

RewriteEngine on
RewriteBase /

RewriteRule ^account/([^/\.]+)/?$ account.php?req=$1 [L,NC,QSA]
RewriteRule ^questions/([^/\.]+)/?$ questions.php?id=$1 [L,NC,QSA]
RewriteRule ^profile/([^/\.]+)/?$ profile.php?id=$1 [L,NC,QSA]

将来必要になった場合は、これらの動作に基づいて新しいルールを追加できるはずです。

于 2012-12-24T09:25:07.417 に答える
0

このような複雑な操作には、PHPと組み合わせたファイルを使用する必要があり.htaccessます。SOで同様の質問をした後、URLの書き換えに関する記事を書きました。

http://tomsbigbox.com/elegant-url-rewriting/

于 2012-12-24T09:23:07.617 に答える