我假設你的URL看起來像這樣:somesite.com/subfolder/file.extension
。如果URL不同,請提供詳細信息。
將此添加到您的DocumentRoot
的.htaccess
中。
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on
RewriteBase/
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule^- [L]
RewriteCond %{REQUEST_URI} ^/([\w]+)/([\w]+\.[\w]+)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%2 -f
RewriteRule^/%2 [NC,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule^- [L]
RewriteRule^/index.php [L]
改變,以適應OP的要求。
RewriteEngine on
RewriteBase/
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule^- [L]
RewriteCond %{REQUEST_URI} ([\w]+\.[\w]+)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%1 -f
RewriteRule^/%1 [NC,L]
RewriteCond %{REQUEST_URI} ([\w]+\.[\w]+)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/subdir/%1 -f
RewriteRule^/subdir/%1 [L]
RewriteRule^/index.php [L]
的後續問題 - > http://stackoverflow.com/questions/9330058/mod-rewrite-redirect-request-to-subdir-with-many-subfolders-of-different-struct – Seba 2012-02-17 14:34:40