需要 htaccess 帮助

发布于 2024-10-01 09:06:17 字数 406 浏览 0 评论 0原文

我想将 http:mydomain.com 重定向到 http://www.mydomain.com。 另外,我还需要包含一个条件

RewriteCond $1 !^(index\.php|images|css|uploads|editor|albums|js|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

,并且我有重定向代码,

RewriteCond %{HTTP_HOST} ^mydomain\.com 
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,NC]

如何将这两个条件合并到一个 htaccess 文件中?

-阿伦

I want to redirect the http:mydomain.com to http//www.mydomain.com.
Also I need to include one more condition

RewriteCond $1 !^(index\.php|images|css|uploads|editor|albums|js|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

And I have redirect code as

RewriteCond %{HTTP_HOST} ^mydomain\.com 
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,NC]

How to combine these two in a single htaccess file?

-Arun

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

骄兵必败 2024-10-08 09:06:17

将它们复制并粘贴到一个 .htaccess 文件中就足够了。这两者没有理由不能放在一个 .htaccess 中。不过,您应该先运行 www :

RewriteEngine On    
RewriteCond %{HTTP_HOST} ^mydomain\.com 
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,NC]

RewriteCond $1 !^(index\.php|images|css|uploads|editor|albums|js|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

Copy and paste them together in one .htaccess file should be enough. There's no reason those two are not able to be together in one .htaccess. You should have the www one run first though:

RewriteEngine On    
RewriteCond %{HTTP_HOST} ^mydomain\.com 
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,NC]

RewriteCond $1 !^(index\.php|images|css|uploads|editor|albums|js|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
吻泪 2024-10-08 09:06:17

Litso 的答案对我来说看起来是正确的,但无论如何请尝试这个..

RewriteEngine On    
RewriteCond %{HTTP_HOST} ^mydomain\.com 
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,NC]

RewriteCond %{REQUEST_URI} !^(index\.php|images|css|uploads|editor|albums|js|robots\.txt)
RewriteRule (.*) index.php/$1

我已经替换了 $!在第二个条件中,并从规则中删除了多余的 ^$ 锚点。

Litso's answer looks right to me but try this anyway..

RewriteEngine On    
RewriteCond %{HTTP_HOST} ^mydomain\.com 
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,NC]

RewriteCond %{REQUEST_URI} !^(index\.php|images|css|uploads|editor|albums|js|robots\.txt)
RewriteRule (.*) index.php/$1

I've replaced $! in the second condition and removed the redundant ^$ anchors from the rules.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文