我一直在研究一個我在php中創建的框架,它的基本部分是發送所有的url查詢到index.php文件夾中。 我設法在我的.htaccess文件.htaccess重定向到任何目錄中的index.php
# Turn rewriting on
Options +FollowSymLinks
RewriteEngine On
# Redirect requests to index.php
#RewriteRule ^(phpmyadmin)($|/) - [L]
RewriteRule ^(html)($|/) - [L]
RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !.*\.png$ [NC]
RewriteCond %{REQUEST_URI} !.*\.jpg$ [NC]
RewriteCond %{REQUEST_URI} !.*\.css$ [NC]
RewriteCond %{REQUEST_URI} !.*\.gif$ [NC]
RewriteCond %{REQUEST_URI} !.*\.js$ [NC]
RewriteRule .* /index.php
做在folloowing代碼時,我的網站移動到不同的文件夾,例如
www.mydomain.com/subdir/{where the index.php is, along with htaccess}
,並停止在這裏工作出現問題。如果我將框架應用程序移動到子域,也會發生同樣的情況。
所以我試圖修改.htaccess來正確地重寫index.php在.htaccess文件所在的位置,而不管它是否在子目錄或子域中。我怎樣才能讓.htaccess知道應用程序在子目錄中並正確地重寫了它,所以位置改變不會中斷指向正確文件的.htaccess?
www.domain.com/{.htaccess+index.php + framework} => works properly
www.subdom.domain.com/{.htaccess+index.php + framework} => does not work
www.domain.com/subdir/{.htaccess+index.php + framework} => does not work //send to www.domain.com/index.php
localhost/projectname/{.htaccess+index.php + framework} =>does not work
正如你所看到的,它需要發送請求到index.php,其中htaccess也位於。
變化'/ index.php'只是'index.php'?當然現在你需要在EVERY目錄中有一個index.php。 – 2014-08-29 18:27:29
正在使用'RewriteBase'不是你的選擇嗎?有了它,當需要移動時需要移動時,可以通過在「.htaccess」中更改2個條目來輕鬆解決問題。 'RewriteBase/folder_it_is_now /'和你的'/ index.php'到'RewriteRule'的'index.php'中。 – Prix 2014-08-29 18:58:38
@Prix你能提供任何樣品嗎?我不是很瞭解。 – Justin 2014-08-29 19:01:32