【问题标题】:Change url in htaccess didnt work在 htaccess 中更改 url 无效
【发布时间】:2014-03-26 20:21:39
【问题描述】:

我有这个网址

   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

【问题讨论】:

  • 你得到的是 404 还是什么?
  • @anubhava 编辑了我得到的内容。

标签: .htaccess url url-rewriting


【解决方案1】:

您可以使用这些规则:

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]

编辑:根据下面的 cmets:

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

【讨论】:

  • Hej:)!很抱歉再次打扰您:),我改变了主意:),我想将这个mywebsite/chat.php?room=somenameHere 更改为这个mywebsite/chat?room=somenameHere,只需删除 php 扩展名,非常感谢。
猜你喜欢
  • 1970-01-01
  • 2012-07-15
  • 1970-01-01
  • 2012-12-10
  • 2016-08-16
  • 2014-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多