"http://localhost/jsfweb/cat/query/"
こんにちは私はクエリがmysqlデータベースからいくつかの結果を返す文字列であるタイプのいくつかのURLに出くわしました。私はこのタイプのURLに精通していますが"http://localhost/jsfweb/cat.php?query=query"
、phpでそれらのURLを使用するにはどうすればよいですか?
5 に答える
You can do this by rewriting url in htaccess file by this :
RewriteRule ^cat/(.*)$ cat.php?query=$1
Use modrewrite
You do something like this: Inside a file named '.htaccess'
Options +FollowSymlinks
Options -MultiViews
RewriteEngine on
RewriteBase /php/eclipse/ShiftPlus2/
#forbidden area
#RewriteCond %{THE_REQUEST} index\.php
#RewriteRule ^index\.php$ http://localhost/php/eclipse/ShiftPlus2/? [R=301]
#unique case
RewriteRule ^email$ email.html [L]
#general case
RewriteRule ^([a-zA-Z_]*)/?$ index.php?query=$1 [L]
RewriteRule ^([a-zA-Z_]+)/([a-z]+)/?$ index.php?query=$1&action=$2 [L]
RewriteRule ^([a-zA-Z_]+)/(-?\d+)/?$ index.php?query=$1&id=$2 [L]
RewriteRule ^([a-zA-Z_]+)/([a-z]+)/(-?\d+)/?$ index.php?query=$1&action=$2$id=$3 [L]
RewriteRule ^([a-zA-Z_]+)/(\w+)/?$ index.php?query=$1&special=$2 [L]
#RewriteRule ^index.php$ login [R]
Where on the left side, there is a Rewrite rule with a regular expression and on the right, this is the real link like you know.
Apacheのmod_rewriteを見てください。ほとんどのWebサイトでは、そのモジュールを介して実行されます。手を汚したくない場合は、それを組み込んだある種のMVCフレームワークを採用できます。
Apache mod_rewrite is what you want. This is an excellent read for beginners:
CodeIgniter (MVC framework) works by accepting a single entry point to the application, then routing according to what follows. So say you declare index.php as the default document, then /index.php/controller/view is the same as /controller/view. The parameters controller and view are used to instantiate and run the appropriate classes.