开发者

Creating friendly URLs with mod_rewrite in htaccess?

开发者 https://www.devze.com 2023-04-12 18:41 出处:网络
I have searched this forum and have done extensive google search and ha开发者_如何学Gove not been able to figure it out. I have many links that look like:

I have searched this forum and have done extensive google search and ha开发者_如何学Gove 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?


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".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号