简体   繁体   English

用.htaccess重写index.php页面后获取404

[英]Getting 404 after rewriting with .htaccess for index.php page

I have a domain call http://www.example.com . 我有一个域名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 . 因此它类似于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 . 因此,就像他们创建了一个调查并为它提供了一个文件夹名称(如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. 我用*在cpanel中创建了一个条目,所以当我们打开http://username.example.com时 ,它进入了index.php,在index.php上,我已经应用了条件,如果有任何子域,那么我们就不会显示默认的索引页面,并显示调查页面,但是如果我们要使用文件夹名称访问http://username.example.com/survey ,则它会给我404。

Now i am rewriting rule in .htaccess to get the folder name but i am getting 404 error? 现在,我正在重写.htaccess中的规则以获取文件夹名称,但是却出现404错误?

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 Ravinder

You can use this rule in root .htaccess: 您可以在根.htaccess中使用此规则:

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com$ [NC]
RewriteRule ^(.+)/?$ /index.php?survey=$1 [,QSA]

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

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