【发布时间】:2017-03-18 17:13:19
【问题描述】:
我是 .htaccess 的新手,在重写某些 URL 时遇到问题。
我的网站是用 php 制作的,有 2 个参数:param1 和 param2。 URL 类似于:
www.website.com/index.php?param1=12345678
www.website.com/index.php?param1=09876543
www.website.com/index.php?param2=abcdefgh
www.website.com/index.php?param2=qwertzui
我想创建一个.htaccess文件来删除“index.php”,将param1和param2替换为2个名称,并在末尾添加“.html”,所以它们变成了:
www.website.com/budget/12345678.html
www.website.com/budget/09876543.html
www.website.com/user/abcdefgh.html
www.website.com/user/qwertzui.html
我有这个代码(从互联网复制)。 它删除了 .php 扩展名,但在内部转发中,它在 URL 的末尾重写了它,忽略了参数。
有人这么好心帮我写代码吗?
谢谢:)
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
【问题讨论】:
标签: php .htaccess url-rewriting