.htaccess change a path to a query strings(.htaccess 更改查询字符串的路径)
问题描述
我在 example.com/中有文件
I have files in example.com/
contact.php
recent.php
videos.php
watch.php
example.com/page/
> /page/
不是文件夹.但我想处理其他文件夹
example.com/page/
> /page/
is not a folder. but i want to work other folders
contact.php(无分页)
contact.php (no pagination)
example.com/page/contact
recent.php (分页>recent.php?page=2
)
recent.php (pagination > recent.php?page=2
)
example.com/page/recent
example.com/page/recent?page=2
watch.php (无分页 > watch.php?title=drama-name
)
watch.php (no pagination > watch.php?title=drama-name
)
example.com/page/watch/drama-name
videos.php(分页获取名称>videos.php?name=drama-name&page=2
)
videos.php (pagination with get name > videos.php?name=drama-name&page=2
)
example.com/page/videos/drama-name
example.com/page/videos/drama-name?page=2
这是我的完整 htaccess 代码 (example.com/.htaccess)
Here is my full htaccess codes (example.com/.htaccess)
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,NE,L]
RewriteRule ^page/playlist$ /playlist.php [L]
RewriteRule ^page/submit$ /submit.php [L]
RewriteRule ^page/contact$ /contact.php [L]
RewriteRule ^page/search$ /search.php [L]
RewriteRule ^page/recent$ /recent.php [L]
RewriteRule ^page/watch/([^/]+)? /watch.php?title=$1
RewriteRule ^page/videos/([^/]+)? /videos.php?name=$1
但在 /page/videos/drama-name?page=2
中不起作用如何解决?它有另一个问题吗?
But not work in /page/videos/drama-name?page=2
how to fix it? it has another problem?
推荐答案
您可以使用 QSA
标志组合正则表达式并缩短 .htaccess 中的规则:
You can combine regex and shorten your rules in your .htaccess with QSA
flag:
RewriteEngine on
RewriteBase /
# add www in host name
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*?)/?$ http://www.%{HTTP_HOST}/$1 [R=301,NE,L]
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [NE,R=301,L]
RewriteRule ^page/(submit|contact|search|recent|playlist)/?$ $1.php [L,NC]
RewriteRule ^page/(videos|watch)/([^/]+)/?$ $1.php?title=$2 [L,QSA,NC]
这篇关于.htaccess 更改查询字符串的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.htaccess 更改查询字符串的路径
基础教程推荐
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01