Ghulam
Ghulam

Reputation: 21

How to redirect to an alias folder using htaccess?

I have a url http://www.example.com/chatroom/chats.php?chat=hey dear

I want a url to be http://www/example.com/chatroom/chats/hey dear

where chatroom is an alias folder.

my apache document root is pointing to a specific folder as 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.

Upvotes: 0

Views: 1086

Answers (2)

Samay
Samay

Reputation: 471

You need to place a .htaccess file in chatroom folder with the following content.

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.webconfs.com/web-tools/url-rewriting-tool/

Upvotes: 0

Vijay Wilson
Vijay Wilson

Reputation: 516

Set QSA flag for your rule and try

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

QSA - Query String Append

Upvotes: 1

Related Questions