Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用.htaccess重写url_.htaccess_Mod Rewrite - Fatal编程技术网

用.htaccess重写url

用.htaccess重写url,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我在数据库中创建了witch display主题的页面。它是topic.php?id=35,它将指向一个主题。我想用.htaccess对/topics/id/idnumberher 你知道我该怎么做吗 RewriteEngine on RewriteRule ^topics/id/([0-9][0-9])$ /topics/id/$1/ [R] RewriteRule ^topics/id/([0-9][0-9])/$ /topic.php?id=$1 我认为这将转变为。。不完全确定 可以找到

我在数据库中创建了witch display主题的页面。它是
topic.php?id=35
,它将指向一个主题。我想用.htaccess对
/topics/id/idnumberher

你知道我该怎么做吗

RewriteEngine on
RewriteRule ^topics/id/([0-9][0-9])$ /topics/id/$1/ [R]
RewriteRule ^topics/id/([0-9][0-9])/$ /topic.php?id=$1
我认为这将转变为。。不完全确定


可以找到更多信息

尼尔斯的想法是正确的。但这更简洁一些,适用于2位数以外的ID

RewriteEngine On
RewriteRule ^topics/id/(\d+)/?$ /topic.php?id=$1 [L]
另外,如果这是为了搜索引擎优化,我建议删除
/id/
部分。它不提供关键字值,并且作为子目录实际上可以降低页面值