简体   繁体   English

如何使用htaccess重定向到别名文件夹?

[英]How to redirect to an alias folder using htaccess?

I have a url http://www.example.com/chatroom/chats.php?chat=hey dear 我有一个网址http://www.example.com/chatroom/chats.php?chat=hey亲爱的

I want a url to be http://www/example.com/chatroom/chats/hey dear 我希望网址为http://www/example.com/chatroom/chats/嘿,亲爱的

where chatroom is an alias folder. 其中chatroom是别名文件夹。

my apache document root is pointing to a specific folder as DocumentRoot 我的Apache文档根目录指向一个特定的文件夹作为DocumentRoot

/var/www/html/myweb

I am trying like 我正在尝试像

RewriteEngine on
RewriteBase /
RewriteRule ^chatroom/([A-Za-z0-9-]+)/?$ chats.php?chat=$1 [NC]

Its saying 俗话说

404 not found. 找不到404。

You need to place a .htaccess file in chatroom folder with the following content. 您需要将.htaccess文件放入带有以下内容的聊天室文件夹中。

Options +FollowSymLinks
RewriteEngine on
RewriteRule chats/(.*) chats.php?chat=$1

Or the following if placing in root folder 或以下内容(如果放在根文件夹中)

RewriteEngine On
RewriteRule ^([^/]*)$ /chatroom/chats.php?chat=$1 [L]

Here are some tools which might help you to generate the such code. 这里有一些工具可以帮助您生成这样的代码。

http://www.generateit.net/mod-rewrite/index.php http://www.generateit.net/mod-rewrite/index.php

http://www.webconfs.com/web-tools/url-rewriting-tool/ http://www.webconfs.com/web-tools/url-rewriting-tool/

Set QSA flag for your rule and try 为您的规则设置QSA标志并尝试

RewriteRule ^chatroom/(.*) chats.php?chat=$1 [QSA,L]

QSA - Query String Append QSA-查询字符串追加

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM