如果不存在特定关键字,则将规则重写为仅重定向

时间:2016-06-04 06:11:30

标签: php apache .htaccess

我正在编写特定的规则,在我的基本URL之后,任何关键字都将被重定向到文件夹子域名/ 例如www.xyz.com/hdaCompany将重定向到www.xyz.com/subdomains/hdaCompany。 但我想要几个关键字的例外,不要重定向到子域,但有自己的规则,如搜索结果。 但问题是它将所有内容路由到子域,因此搜索结果网址不起作用这是我的.htaccess

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /

        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule    ^search-result/(.*)/(.*)/(.*)/(.*)/(.*)?$    search-result.php?BtnSearch=$1&SearchTerm=$2&Location=$3&Rating=$4&Keyword=$5     
        RewriteRule    ^search-result/([a-zA-Z0-9-/]+)/([a-zA-Z0-9-/]+)/([a-zA-Z0-9-/]+)/?$    search-result.php?BtnSearch=$1&SearchTerm=$2&Location=$3   
        RewriteRule    ^search-result/([a-zA-Z0-9-/]+)/([a-zA-Z0-9-/]+)/?$    search-result.php?BtnSearch=$1&SearchTerm=$2 
        RewriteRule    ^special-deal/(.*)/(.*)/(.*)/(.*)/(.*)?$    special-deal.php?BtnSearch=$1&SearchTerm=$2&Location=$3&Rating=$4&Keyword=$5  
        RewriteRule ^(.*)$ subdomains/$1 [L]

</IfModule>
<FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css)$">
    ExpiresActive On
    ExpiresDefault A2592000
</FilesMatch>
<FilesMatch "^/data/*.php">
    Header set Cache-Control "no-cache"
</FilesMatch>

1 个答案:

答案 0 :(得分:0)

这很简单......我就是这样做的

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /

        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d


    RewriteCond %{REQUEST_URI} !^/search-result.* 
    RewriteCond %{REQUEST_URI} !^/special-deal.* 
    RewriteRule     ^(.*)$ subdomains/$1

    RewriteRule    ^search-result/(.*)/(.*)/(.*)/(.*)/(.*)?$    search-result.php?BtnSearch=$1&SearchTerm=$2&Location=$3&Rating=$4&Keyword=$5     
        RewriteRule    ^search-result/([a-zA-Z0-9-/]+)/([a-zA-Z0-9-/]+)/([a-zA-Z0-9-/]+)/?$    search-result.php?BtnSearch=$1&SearchTerm=$2&Location=$3   
        RewriteRule    ^search-result/([a-zA-Z0-9-/]+)/([a-zA-Z0-9-/]+)/?$    search-result.php?BtnSearch=$1&SearchTerm=$2 
        RewriteRule    ^special-deal/(.*)/(.*)/(.*)/(.*)/(.*)?$    special-deal.php?BtnSearch=$1&SearchTerm=$2&Location=$3&Rating=$4&Keyword=$5


</IfModule>
<FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css)$">
    ExpiresActive On
    ExpiresDefault A2592000
</FilesMatch>
<FilesMatch "^/data/*.php">
    Header set Cache-Control "no-cache"
</FilesMatch>