RewriteEngine On
RewriteBase /
# Use the following rule if you want to make the page like a directory
RewriteRule ^(v)$ /$1/
# The following rule does the rewrite.
RewriteRule ^(.+)/$ profile.php?name=$1
# The following rewrite the other way round:
RewriteCond %{REQUEST_URI} ^/profile.php
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD|TRACE)\ /profile.php
RewriteCond %{QUERY_STRING} name=([^&]+)
RewriteRule ^profile.php$ %1?
我在我的 .htaccess 文件中执行上面的代码,这在我的 profile.php 页面中运行良好,因为之前,我的 profile.php 显示这种 URL:
http://mysite.com/profile.php?name=john
但是当我编写该代码时,结果如下:
http://mysite.com/john/
我还想将此代码应用于我的 category.php,所以我所做的只是复制上面的代码,我的整个 .htaccess 文件看起来像这样:
RewriteEngine On
RewriteBase /
# Use the following rule if you want to make the page like a directory
RewriteRule ^(v)$ /$1/
# The following rule does the rewrite.
RewriteRule ^(.+)/$ profile.php?name=$1
RewriteRule ^(.+)/$ category.php?cid=$1
# The following rewrite the other way round:
RewriteCond %{REQUEST_URI} ^/profile.php
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD|TRACE)\ /profile.php
RewriteCond %{QUERY_STRING} name=([^&]+)
RewriteRule ^profile.php$ %1?
RewriteCond %{REQUEST_URI} ^/category.php
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD|TRACE)\ /category.php
RewriteCond %{QUERY_STRING} cid=([^&]+)
RewriteRule ^category.php$ %1?
但是这段代码给了我一个奇怪的结果,因为当我访问
http://mysite.com/john/
我看到的内容是我的 category.php 的内容。
我应该在这里做什么?任何帮助将不胜感激和奖励!
谢谢!