I have a domain call http://www.example.com .
On this website users come and register with a username and they get a subdomain of their username. So it gets like http://username.example.com .
When they login and go into their admin panel, they can create survey for the users to fill out. At a time they can create multiple surveys and they can give specific folder name to each survey. So like they created a survey and gave it a folder name like http://username.example.com/survey .
I have created a entry in cpanel with * so when we open http://username.example.com , so it goes to index.php and on index.php i have applied condition that if any subdomain is there then we won't show the default index page and will show the survey page, but if we are going for http://username.example.com/survey with a folder name then it is giving me 404.
Now i am rewriting rule in .htaccess to get the folder name but i am getting 404 error?
This is the rule i am having right now.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
</IfModule>
I don't understand what will be the rule to get a folder name. I searched a lot but couldn't get it working.
Can someone please help me or guide me with this?
Thanks for any help.
Ravinder
You can use this rule in root .htaccess:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteRule ^(.+)/?$ /index.php?survey=$1 [,QSA]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.