htaccess的500错误。重写规则没有工作,因为它应该重写、因为它、规则、错误

2023-09-02 10:10:15 作者:是谁,倾了城

我和我的.htaccess重写规则中的一个问题: 服务器的详细信息: 服务器运行的Litespeed Web服务器而不是Apache,根据我的主机提供商它与Apache的mod_rewrite 100%兼容。 问题: 我得到500内部服务器错误,当我使用code:

 < IfModule mod_rewrite.c>
  选项​​+的FollowSymLinks
  选项​​+指标
   RewriteEngine叙述上
   的RewriteBase /
   的RewriteCond%{HTTP_HOST}!^ WWW  .mysite  .COM $ [NC]
   的RewriteCond%{HTTP_HOST} ^(WWW)([A-Z0-9  - ] +)?mysite.com $ [NC]
   重写规则^(。*)$%2 / $ 1 [L,QSA,NC]
< / IfModule>
 

当我使用这个code,它pretty的很多做的事情是该做重定向流量来自任何子域到相应的子文件夹中的文件要求也。没有错误,什么都没有它的工作原理确定的,但它也改变了,我不希望在浏览器的地址。

 < IfModule mod_rewrite.c>
  选项​​+的FollowSymLinks
  选项​​+指标
   RewriteEngine叙述上
   的RewriteBase /
   的RewriteCond%{HTTP_HOST}!^ WWW  .mysite  .COM $ [NC]
   的RewriteCond%{HTTP_HOST} ^(WWW)([A-Z0-9  - ] +)?mysite.com $ [NC]
   重写规则^(。*)$ http://mysite.com/%2/$1 [L,QSA,NC]
< / IfModule>
 

任何想法?

Editetd:有一件事我想提的是,我使用通配符DNS的子域不存在真的。 再次Editted:重写规则^(。*)$%2 /的index.php [L,QSA,NC]如果我使用这个规则,并尝试一个存取权限的 http://sub.mysite.com/whatever 它succesfuly重定向到的 http://mysite.com/sub/index.php 我不明白为什么它不使用$来代替的index.php 1工作时,我改变他们,我得到500内部服务器错误。

APACHE支持.htaccess伪静重写出错Noinputfilespecified的解决方案 其它代码类资源 CSDN下载

现在得到了解决:

 < IfModule mod_rewrite.c>
选项​​+的FollowSymLinks
选项​​+指标
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{ENV:REDIRECT_STATUS} 200!
的RewriteCond%{HTTP_HOST} ^(。*)的mysite  .COM $ [NC]
的RewriteCond%{HTTP_HOST}!^ WWW  * [NC]
重写规则^ $ HTTP(*)://www.%1mysite.com/$1 [R = 301,L,QSA] [NC]
的RewriteCond%{HTTP_HOST}!^ WWW  .mysite  .COM $ [NC]
的RewriteCond%{HTTP_HOST} ^(WWW)([A-Z0-9  - ] +)?mysite.com $ [NC]
的RewriteCond%2 == $ 1!^(。*)==  1
重写规则^(。*)%,2 / $ 1 $ 2 $ 3 [L,QSA,NC]
< / IfModule>
 

解决方案

这是一个有趣的普遍的问题,值得一个通用的解决方案,所以怎么样:

 #
#规则的模式匹配('弗雷德','','')弗雷德
#('123','/',弗雷德)的模式'123 /弗雷德
#在COND 2%2是子域例如123 www.123.mysite.com
#因此COND 3模式是123 == 123 www.123.mysite.com/123/fred
#这将匹配^(。*?)==  1或失败的否定
#
的RewriteCond%{HTTP_HOST}!^ WWW  .mysite  .COM $ [NC]
的RewriteCond%{HTTP_HOST} ^(WWW)([A-Z0-9  - ] +)?mysite.com $ [NC]
的RewriteCond%2 == $ 1!^(。*?)==  1
重写规则^([^ /] *)(/?)(。*)%1 / $ 1 $ 2 $ 3 [L]
 

I have a problem with one of my .htaccess rewriterule: Server details: Server runs LiteSpeed Webserver not Apache, according to my host provider it's 100% compatible with apache mod_rewrite. Problem: I get 500 Internal Server Error when i use this code:

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  Options +Indexes  
   RewriteEngine On
   RewriteBase /
   RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
   RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).mysite.com$ [NC]
   RewriteRule ^(.*)$  %2/$1 [L,QSA,NC]
</IfModule>

When I use this code, it pretty much does what it is suppose to do it redirects traffic from any sub-domain to a corresponding sub-folder with file request also. No Error, no nothing it works OK but it also changes the browser's address which i don't wish.

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  Options +Indexes  
   RewriteEngine On
   RewriteBase /
   RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
   RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).mysite.com$ [NC]
   RewriteRule ^(.*)$  http://mysite.com/%2/$1 [L,QSA,NC]
</IfModule>

Any ideas?

Editetd : One thing i would like to mention is that i use wildcard DNS the subdomain don't realy exist. Editted yet again : RewriteRule ^(.*)$ %2/index.php [L,QSA,NC] if i use this rule and try to acces a http://sub.mysite.com/whatever it succesfuly redirects it to http://mysite.com/sub/index.php i don't get it why it does not work with $1 instead of index.php when i change them i get 500 internal server error.

Got the solution now :

<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes  
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{HTTP_HOST} ^(.*)mysite.com$ [NC]
RewriteCond   %{HTTP_HOST} !^www.* [NC]
RewriteRule ^(.*)$ http://www.%1mysite.com/$1 [R=301,L,QSA] [NC]
RewriteCond %{HTTP_HOST}     !^www.mysite.com$              [NC]
RewriteCond %{HTTP_HOST}     ^(www.)?([a-z0-9-]+).mysite.com$ [NC]
RewriteCond %2==$1           !^(.*)==1                                        
RewriteRule ^(.*) %2/$1$2$3   [L,QSA,NC]
</IfModule>

解决方案

This is an interesting generic problem which merits a generic solution, so how about:

#
# Rule matches ('fred','','')    for pattern 'fred'
#              ('123','/',fred') for pattern '123/fred'
# At cond 2 %2 is the subdomain e.g. 123 for www.123.mysite.com
# Hence cond 3 pattern is 123==123 for www.123.mysite.com/123/fred
# and this will match ^(.*?)==1 or fail its negation
#
RewriteCond %{HTTP_HOST}     !^www.mysite.com$              [NC]
RewriteCond %{HTTP_HOST}     ^(www.)?([a-z0-9-]+).mysite.com$ [NC]
RewriteCond %2==$1           !^(.*?)==1                                        
RewriteRule ^([^/]*)(/?)(.*) %1/$1$2$3                        [L]