【问题标题】:How to add new router to the mod_rewrite如何将新路由器添加到 mod_rewrite
【发布时间】:2016-11-16 23:38:58
【问题描述】:

我有一些 mod_rewrite 配置,将所有请求重定向到 /index.php 路由器。我想为某种路径添加新路由器,例如:对 /path/action 的请求应使用 /custom_engine/index.php 文件处理。这种情况怎么办?

我现有的 .htaccess:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On

# Get rid of index.php
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule (.*) index.php?rewrite=2 [L,QSA]

# Rewrite all directory-looking urls
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*) index.php?rewrite=1 [L,QSA]

# Try to route missing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} public\/ [OR]
RewriteCond %{REQUEST_FILENAME} \.  (jpg|gif|png|ico|flv|htm|html|php|css|js)$
RewriteRule . - [L]

# If the file doesn't exist, rewrite to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]

</IfModule>

【问题讨论】:

    标签: php .htaccess mod-rewrite apache2


    【解决方案1】:
    <IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteRule (path/action/)(.*) engine-v2/index.php [L,NC]
    
    # Get rid of index.php
    RewriteCond %{REQUEST_URI} /index\.php
    RewriteRule ^(path/action/)(.*) index.php?rewrite=2 [L,QSA]
    
    # Rewrite all directory-looking urls
    RewriteCond %{REQUEST_URI} /$
    RewriteRule (.*) index.php?rewrite=1 [L,QSA]
    
    # Try to route missing files
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} public\/ [OR]
    RewriteCond %{REQUEST_FILENAME} \.(jpg|gif|png|ico|flv|htm|html|php|css|js)$
    RewriteRule . - [L]
    
    # If the file doesn't exist, rewrite to index
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?rewrite=1 [L,QSA]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-12
      • 2021-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-23
      • 1970-01-01
      相关资源
      最近更新 更多