我想更改网站的网址:
http://example.com/clinicdetails.php?url=/diet-clinic-in-punjabi-bagh.html
看起来像这样:
http://example.com/clinicdetails.php/diet-clinic-in-punjabi-bagh.html
.htaccess
文件中的代码如下:
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /clinicdetails.php?url=$1 [L]
但是,这在我的localhost上不起作用(没有错误),也不在共享主机服务器上。这可能是什么问题?
答案 0 :(得分:0)
RewriteRule ^([^/]*)\.html$ /clinicdetails.php?url=$1 [L]
The RewriteRule
pattern is failing to match the given URL because of the start of string anchor ^
. Whilst you don't have slashes in the path segment you are trying to match, you do in the rest of the URL. So, try the following:
RewriteRule ([^/]+)\.html$ /clinicdetails.php?url=/$1 [L]
I've also changed the *
to +
, since the filename is at least 1 char. A more specific regex is better.
To map to your desired URL, you would also seem to require a slash prefix on the URL param value. ie. url=/$1