1

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

4
  • I i unclear what the problem is? Is http://username.example.com/survey showing 404? What URL do you want to show. Commented Mar 8, 2014 at 4:01
  • In username.example.com/survey, /survey is the unique name for that specific survey, i want to get this name so i can fetch all the questions of this survey and show it to user. But i couldn't write rewrite rule for it so it is giving me 404 Commented Mar 8, 2014 at 5:21
  • Once captured what URL should it be rewritten to. Is it something like /index.php?survey=abcd where abcd is survey name Commented Mar 8, 2014 at 5:24
  • Yes i want to get whatever comes after username.example.com because /survey will come dynamically for each survey so if he creates another survey he can do it like username.example.com/newsurvey. So i want to get the /newsurvey as a parameter or query string Commented Mar 8, 2014 at 5:33

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.