在 htaccess 中使用 mod_rewrite 创建友好的 URL?
我搜索过这个论坛并进行了大量的谷歌搜索,但无法弄清楚。我有很多链接,如下所示:
mysite.com/example6.php?id=play-game
mysite.com/example6.php?id=watch-tv
mysite.com/example6.php?id=go-outside
我已经尝试了很多不同的代码,将其放入我的 .htaccess 文件中:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /example6.php?id=$1 [L]
以及
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^id/(.*) example6.php?id=$1
</IfModule>
更多的尝试,但没有任何效果可以让我的 URL 看起来像这样:
mysite.com/example6/play-game
mysite.com/example6/watch-tv
mysite.com/example6/go-outside
我愿意我的服务器上启用了 mod_rewrite。有人有什么想法吗?
I have searched this forum and have done extensive google search and have not been able to figure it out. I have many links that look like:
mysite.com/example6.php?id=play-game
mysite.com/example6.php?id=watch-tv
mysite.com/example6.php?id=go-outside
I have tried lots of different code putting this in my .htaccess file:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /example6.php?id=$1 [L]
and
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^id/(.*) example6.php?id=$1
</IfModule>
and many more attempts but nothing works to get my URLS to look like this:
mysite.com/example6/play-game
mysite.com/example6/watch-tv
mysite.com/example6/go-outside
I do have mod_rewrite enabled on my server. Does anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
您的第一个示例 (
RewriteRule ^([^/]*)\.html$ /example6.php?id=$1 [L]
) 将正确适用于“/play-game”之类的网址.html”,而您的第二个示例 (RewriteRule ^id/(.*) example6.php?id=$1
) 将正确适用于“/id/play-game”等网址。Try this:
Your first example (
RewriteRule ^([^/]*)\.html$ /example6.php?id=$1 [L]
) would correctly work for urls like "/play-game.html", and your second example (RewriteRule ^id/(.*) example6.php?id=$1
) would correctly work for urls like "/id/play-game".