Apache Htaccess转发子文件夹

时间:2014-01-02 08:43:24

标签: apache .htaccess mod-rewrite

我想为htaccess创建自定义规则,以便主文件夹中请求的所有网址(例如localhost/asfsd)都会重定向到localhost/index.php?url=asfsd,但如果用户输入以下网址{ {1}}然后必须将其转发至localhost/asfsd-。这是我当前的localhost/info.php?url=asfsd配置:

.htaccess

2 个答案:

答案 0 :(得分:0)

试试这个

RewriteEngine on  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule ^(.*)\-$ info.php?url=$1 [L,QSA]
RewriteRule ^(.*) index.php?url=$1 [L,QSA]

答案 1 :(得分:0)

您可以尝试以下两条规则:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule ^(.+?)-$ /info.php?url=$1 [L,QSA]  

RewriteCond %{REQUEST_FILENAME} !-f  
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteRule ^(.*)$ /index.php?url=$1 [L,QSA]