php - .htaccess URL 用一个和两个查询字符串变量重写

标签 php apache .htaccess url-rewriting

我是第一次尝试重写 URL,我有以下需要重写的 URL:

http://domain.com/resorts.php?countryname=Portugal
http://domain.com/rss.php?destination=Torremolinos&itemtype=rfamily

我在我的 .htaccess 文件中写了以下内容:

Options +FollowSymLinks
RewriteEngine on

RewriteRule /countryname/(.*)/ resorts.php?countryname=$1
RewriteRule /destination/(.*)/itemtype/(.*)/ rss.php?destination=$1&itemtype=$2

但是当我尝试以下操作时,我一直找不到 URL。请有人指出我可能做错了什么?非常感谢。

http://domain.com/countryname/Portugal
http://domain.com/destination/Torremolinos/itemtype/rfamily

最佳答案

你可以使用这个:

Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule countryname/(.*)/? resorts.php?countryname=$1 [NC,L]
RewriteRule destination/(.*)/itemtype/(.*)/? rss.php?destination=$1&itemtype=$2 [NC,L]

关于php - .htaccess URL 用一个和两个查询字符串变量重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8198359/

相关文章:

php - 使用适用于 PHP 的 Azure SDK 将记录插入到 azure 表存储时出现 cURL 错误

php - 访问由数字字符串索引的数组元素

macos - 在 mac os Sierra 上设置 apache Web 服务器(macbook pro 13 2014)

javascript - 使用 Service Worker 时离线重写 URL

PHP 查询到 HTML 单选按钮

php - .htaccess mod_rewrite 错误

mod-rewrite - 在 apache 2.2.3 上设置通配符子域(使用反向代理)

.htaccess - 将http重定向到https,然后将其重定向到子域的文件夹?

ruby-on-rails - bluehost 使用 htaccess 共享 ssl 重定向

java - 无法在 PHP 中重现 Java MessageDigest 哈希