Regex www.rewrite始终重定向到www.mydomain.com/index.php
这实际上是一个常见的问题,你可以找到一些关于这个问题的帖子(例如)。但我尝试的所有重定向对我都不起作用。www.将被添加,但所有参数将丢失 mystore.com/store/view/>重定向至---->www.mystore.com/index.php mystore.com/product/view/10-->重定向到-->www.mystore.com/index.php 这是我试过的一些,应该有效:Regex www.rewrite始终重定向到www.mydomain.com/index.php,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,这实际上是一个常见的问题,你可以找到一些关于这个问题的帖子(例如)。但我尝试的所有重定向对我都不起作用。www.将被添加,但所有参数将丢失 mystore.com/store/view/>重定向至---->www.mystore.com/index.php mystore.com/product/view/10-->重定向到-->www.mystore.com/index.php 这是我试过的一些,应该有效: RewriteCond %{HTTP_HOST} !^$ RewriteCond %{
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
或
谁能给我指一下正确的方向吗?
非常感谢。您可以在根目录中使用此代码。htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^index\.php$ - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L,NC]
您的第一条规则将删除来自非WWW URL的任何内容,而不是保留它,并在内部重定向到
index.php
,你应该保留他的第一条示例规则,这条规则应该可以正常工作,同时保留HTTP/S翻译,以防他使用HTTPS。好吧,我现在添加了它,但我被2个示例操作弄糊涂了,前提是要求重定向到www.mystore.com/index.php
阅读他的问题后,我明白了,他已经让非WWW-to-WWW工作了,但是它不会将它引导到他的控制器(index.php),他希望有一个额外的规则来实现这一点。在他的两个重定向示例中,他都希望将即将出现的URL发送到控制器,您稍后的规则可以很好地执行此操作;)因此+1。感谢@Prix,理解mod_rewrite
问题背后的正确意图有时很棘手。谢谢大家的帮助。我真的很感激!
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^index\.php$ - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L,NC]