English 中文(简体)
将两个模式重写规则合并为规则
原标题:Combine two mod_rewrite rule into one

我要把两条修改规则合并为一条

(1) 在 CMS 中,有索引.php 处理网上的所有查询。 例如,如果 URI 是域名.com/query-string, index.php call/ 包括所需的部件和不愉快的内容。 我用以下方式做:

RewriteCond %{REQUEST_URI} !.[[:alnum:]]+$
RewriteRule ^([^*]+) index.php [L,QSA] 

2) 我需要用 HTTP 301 将永久的 www 移动到非 www 。 例如, www.domain.com 转到域名. com 。

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

但当我把这两条规则都放进 htaccess 文件时,它就停止了工作,也停止了所有链接, 网络上的链接都重新定位了索引.php 和 显示主页。 这就是为什么我需要将这两条规则合并为一条。

.htaccess的开头是:

RewriteEngine On
RewriteBase /

是否有解决办法,如何解决?

整个. httaccess :

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !.[[:alnum:]]+$
RewriteRule ^([^*]+) index.php [L,QSA]

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

我试图重订规则,但没有解决办法。

非常感谢。

最佳回答

这是正确的顺序。 根据迄今为止提供的信息,我认为没有理由不这样做(在测试机器上在这里工作)。如果它仍然不起作用,也许在别的地方还有其他规则(或者在您的 PHP 应用程序中设定了方向)。

RewriteEngine On
RewriteBase /

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

RewriteCond %{REQUEST_URI} !.[[:alnum:]]+$
RewriteRule ^([^*]+) index.php [L,QSA]

BTW ,如果您将 与正则表达式匹配( 模式开头为 < code/ code> ),则最好避开点,因为在某些情况下,它可以产生巨大的不同( 可能不会发生在您身上, 但是, 因为点的意思是“ 任意字符 ” ) - . 或者使用普通字符串比较而不是regex:

问题回答

暂无回答




相关问题
Ignore symlinks in clean URL s in .htaccess

Example URL: example.com/user /user is both a symlinked directory and a valid URL to content on my site. I user Horde Routes to request the content and all requests to the site go through index.php. ...

.htaccess File Options -Indexes on Subdirectories

I have the following .htaccess line, simple no indexes on root. Options -Indexes What do we add so it propagates to any sub directory instead of having to create one file for each? One .htaccess on ...

Mod Rewrite ignoring -d

After a day or two, I am still fighting with Mod Rewrite. It seems that 60% of my development time is spent battling the server. My current URL structure is such that all http://example.com/xyz and ...

ErrorDocument 404 Not Sending Referrer Information: PHP

I m using a standard htaccess ErrorDocument 404 to redirect users to a new page. In order to customize the 404, I need to know their referrer information (from the page they Tried to visit). $...

Find all htaccess files on server [closed]

I m looking for a Linux command to go through all the directories on my server and find all .htaccess files. The output would be a list of all those files with full path, creation/modification date ...

301 Redirect Help with Dynamic URL s and Multiple Id s

I just did a redesign for www.wildchildclothes.com which has a new URL structure. The old site ran on Zen Cart and had a bad URL structure. Here are some examples of what I want to redirect from: OLD:...

热门标签