apache - 具有多参数的 htaccess

标签 apache .htaccess mod-rewrite

我正在尝试像这样重定向我的链接:

my href = example.com/?p=users&page=2
我的网址应该是 = example.com/users/page/2

此时,我的 mod_rewrite 正在处理:

my href = example.com/?p=users
我的网址 = example.com/users

这是我的 htaccess:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
</IfModule>

最佳答案

完整的 .htaccess 如下:

Options +FollowSymLinks
RewriteEngine On

# skip all files and directories from rules below
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# skip index.php from any rules below
RewriteRule ^index\.php$ - [L,NC]

# handle /users/page/2 URI
RewriteRule ^([\w-]+)/([\w-]+)/(\d+)/?$ index.php?p=$1&$2=$3 [L,QSA]

# handle /users URI
RewriteRule ^([\w-]+)/?$ index.php?p=$1 [L,QSA]

关于apache - 具有多参数的 htaccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39516329/

相关文章:

php - 如何重写 SEO 友好的 url,例如 stackoverflow

php - centos+在 php.ini 中启用 mbstring 扩展仍然没有在 phpinfo() 中显示

php - 在 cPanel 中创建自定义 PHP 错误页面,而不将它们从抛出错误的页面重定向

javascript 按字面意思取# 标记

php - .htaccess 在亚马逊 ec2 ubuntu 实例中不工作

php - 如何在类似 MVC 的页面中基于漂亮的 URL 加载类?

apache - 子域在 http 上工作正常,在 https 上不工作

apache - SSL 证书无 WWW Apache (ModRewrite) EV

apache - 无效命令 'RedirectMatch' - Apache 2.47。 Ubuntu 信任

php - SSL 网站在子 URL 中附加 https