Htaccess - mod 重写 "duplicates" 我的路径
Htaccess - mod rewrite "duplicates" my path
我花了很多时间研究 .htaccess,但完全没有成功。
我的问题是:我正在离线使用 wamp 服务器 (localhost)。我的网站位于 wamp 主库的一个文件夹中(我网站的基础 url 如下所示:http://localhost/mydirectoryname, )
我正在尝试创建 .htaccess 文件来重写我讨厌的 urls,但是因为我不熟悉 paths/regular 表达式,所以它工作起来很奇怪。
这是我必须屏蔽的内容:
http://localhost/mydirectoryname/index.php?category=1
这就是我想要实现的(此刻)
http://localhost/mydirectoryname/categories/1.html
起初我的重写工作正常,但之后就变得疯狂了。这就是我得到的(如果我继续点击我网页的菜单(类别)link (a) 按钮不止一次)
http://localhost/mydirectoryname/categories/categories/categories/categories/2.html
我的 .htaccess 文件如下所示:
RewriteEngine On
RewriteRule categories/(.*).html$ index.php?category=
PS:我的最终目标是创造这种url:
http://localhost/mydirectoryname/categories/1/categoryname.html
这样试试:
RewriteBase /mydirectoryname/
RewriteCond %{THE_REQUEST} ^GET\ /(.+)/index\.php\?category=(\d+) [NC]
RewriteRule ^ /%1/categories/%2.html [R=301,L]
RewriteRule ^categories/(\d+)\.html$ index.php?category= [L]
我花了很多时间研究 .htaccess,但完全没有成功。
我的问题是:我正在离线使用 wamp 服务器 (localhost)。我的网站位于 wamp 主库的一个文件夹中(我网站的基础 url 如下所示:http://localhost/mydirectoryname, )
我正在尝试创建 .htaccess 文件来重写我讨厌的 urls,但是因为我不熟悉 paths/regular 表达式,所以它工作起来很奇怪。
这是我必须屏蔽的内容:
http://localhost/mydirectoryname/index.php?category=1
这就是我想要实现的(此刻)
http://localhost/mydirectoryname/categories/1.html
起初我的重写工作正常,但之后就变得疯狂了。这就是我得到的(如果我继续点击我网页的菜单(类别)link (a) 按钮不止一次)
http://localhost/mydirectoryname/categories/categories/categories/categories/2.html
我的 .htaccess 文件如下所示:
RewriteEngine On
RewriteRule categories/(.*).html$ index.php?category=
PS:我的最终目标是创造这种url:
http://localhost/mydirectoryname/categories/1/categoryname.html
这样试试:
RewriteBase /mydirectoryname/
RewriteCond %{THE_REQUEST} ^GET\ /(.+)/index\.php\?category=(\d+) [NC]
RewriteRule ^ /%1/categories/%2.html [R=301,L]
RewriteRule ^categories/(\d+)\.html$ index.php?category= [L]