Apache mod-rewrite不包括顶级域


apache mod-rewrite to not include the top level domain

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !'.(gif|jpg|png|swf|css|html|js|ico|pdf)$
RewriteCond %{REQUEST_URI} !^/app.php$
RewriteCond %{REQUEST_URI} !^/app.php/
RewriteRule ^(.*)$ app.php/$1?%{QUERY_STRING} [L]

好的,所以我已经设法创建了一个漂亮的小。htaccess规则集。它将除了图像、html、js和css之外的所有流量路由到一个名为app.php的php文件。

唯一的问题是,有了这个,它也会把带或不带斜杠的顶级域名路由到app.php。

如何将顶级域添加到此规则集?

如果您想避免转发着陆页,请使用:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !'.(gif|jpg|png|swf|css|html|js|ico|pdf)$
RewriteCond %{REQUEST_URI} !^/app'.php(/.*)?$ [NC]
RewriteRule ^(.+)$ app.php/$1 [L]

.+将匹配任何内容,但不匹配着陆页。

如果你想要排除所有的顶级域名url,那么使用:

RewriteCond %{HTTP_HOST} !^(www'.)?example'.com$ [NC]
RewriteCond %{REQUEST_URI} !'.(gif|jpg|png|swf|css|html|js|ico|pdf)$
RewriteCond %{REQUEST_URI} !^/app'.php(/.*)?$ [NC]
RewriteRule ^(.*)$ app.php/$1 [L]