在htaccess中更改URL无效

时间:2014-03-26 20:21:40

标签: .htaccess url url-rewriting

我有这个网址

   mywebsite/chat.php?room=somenameHere

我想改变它:

   mywebsite/chat/somenameHere

我试过了:

Options +SymLinksIfOwnerMatch -MultiViews

 ## Mod_rewrite in use.

RewriteEngine On
RewriteRule ^videos/([0-9]+)/?$ /details.php?object=1&id=$1 [L,QSA,NC]
RewriteRule ^articles/([0-9]+)/?$ /details.php?object=0&id=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php 
RewriteRule ^chat/([A-Za-z0-9-]+)/?$ chat.php?room=$1 [NC,L]

但没有任何事情发生,它没有用,有什么不对吗?我看了很多教程,都和我说的一样。

感谢您的指导!

编辑:

即时通讯获取同一页面而不更改任何内容且没有错误。得到这个:

  mywebsite/chat.php?room=somenameHere

1 个答案:

答案 0 :(得分:2)

您可以使用以下规则:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /mainwebsite/

RewriteCond %{THE_REQUEST} /chat\.php\?room=([^\s&]+) [NC]
RewriteRule ^ chat/%1? [R=301,L,NE]

RewriteRule ^videos/([0-9]+)/?$ details.php?object=1&id=$1 [L,QSA,NC]
RewriteRule ^articles/([0-9]+)/?$ details.php?object=0&id=$1 [L,QSA,NC]
RewriteRule ^chat/([A-Za-z0-9-]+)/?$ chat.php?room=$1 [NC,L,QSA]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

编辑:根据以下评论:

RewriteCond %{THE_REQUEST} /(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L,NE]