我以前从来不需要使用.htaccess,而且我对编码相当陌生--我正试图将localhost/index.php?id=123456789作为localhost/123456789/来传递,但我无法正确地获得HTaccess,我已经尝试了在这里的prevoius帖子中所能找到的所有东西,哈哈!
我现在的HTACCESS看起来是这样的,但是它不能做我想做的事情。
RewriteEngine On
RewriteRule ^id/(\d+)$ /index.php?id=$1 [NC,QSA,L] 发布于 2016-05-10 00:48:14
您可以使用mod_rewrite在.htaccess中完成它,但是我不确定从您的问题中您希望将它传递到哪个方向。
如果您希望人们在您想要的URL栏中键入php脚本:
RewriteEngine on
RewriteCond %{QUERY_STRING} id=([0-9]+)
RewriteRule ^index.php$ %1/或者,如果您希望用户输入“漂亮”版本,但您的服务器要加载您需要的PHP脚本:
RewriteEngine on
RewriteRule ^([0-9]+)/$ index.php?id=$1&%{QUERY_STRING}对于这两种方式和301重定向到漂亮的URL:
RewriteEngine on
RewriteRule ^([0-9]+)/$ index.php?id=$1&%{QUERY_STRING} [L]
RewriteCond %{QUERY_STRING} id=([0-9]+)
RewriteRule ^index.php$ %1/ [L,R=301]https://stackoverflow.com/questions/37127477
复制相似问题