[英]Creating friendly URLs with mod_rewrite in htaccess?
I have searched this forum and have done extensive google search and have not been able to figure it out. 我已经搜索了这个论坛,并进行了广泛的Google搜索,但无法弄清楚。 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: 我尝试了很多不同的代码,将其放入我的.htaccess文件中:
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: 还有更多尝试,但没有任何办法使我的URL看起来像这样:
mysite.com/example6/play-game
mysite.com/example6/watch-tv
mysite.com/example6/go-outside
I do have mod_rewrite enabled on my server. 我的服务器上确实启用了mod_rewrite。 Does anyone have any ideas? 有人有什么想法吗?
Try this: 尝试这个:
RewriteRule ^example6/(.*)$ example6.php?id=$1 [L]
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". 您的第一个示例( RewriteRule ^([^/]*)\\.html$ /example6.php?id=$1 [L]
)可以正确处理“ /play-game.html”之类的网址,而第二个示例( RewriteRule ^id/(.*) example6.php?id=$1
)对于“ / id / play-game”之类的网址将正确工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.