如何使用.htaccess重写规则和non显示以下URL?范围?
Original URL
http://example.com/index.php?store=1
Desired URL
http://example.com/1/
或者
Desired URL
http://example.com/store/1
我正在尝试遵循.htaccess中的代码。我在这里想念的是什么?
RewriteEngine On
Options +Followsymlinks
RewriteCond %{REQUEST_FILENAME} !-f
rewriteRule ^store/(.+)\$ index.php?store=$1 [L]
我的index.php文件具有此代码
<?php
$storeid = $_GET['store'];
echo $storeid;
?>
我在这里想念的是什么?
您正在转义字符串结尾字符,导致表达式查找文字$
符号,因此它永远不会匹配。
您需要类似:
rewriteRule ^store/(.+)$ /index.php?store=$1 [L]
^ no back-slash here
或者,如果您想确保只匹配数字:
rewriteRule ^store/(\d+)$ /index.php?store=$1 [L]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句