2017-09-14 242 views
0

我在.htaccess中將所有請求重定向到index.php。它的工作原理。 但我看到第二頁上的圖片不顯示。 但顯示主頁上的圖片。 如何配置這些規則?.htaccess將所有請求重定向到index.php

謝謝。

RewriteEngine on 
RewriteBase/

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

RewriteRule ^(.*)$ index.php 
+0

在每個頁面上定義基地href在並將其設置爲您的網站url

+0

請勿在任何地方使用相對鏈接! 'href =「img/some-image.jpg」'應該改成'href =「/ img/some-image.jpg」'。試試看。 – delboy1978uk

回答

0

這是我的.htaccess使用

RewriteEngine On 

# The following rule tells Apache that if the requested filename 
# exists, simply serve it. 

RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 


# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do 
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work 
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution. 

RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$ 
RewriteRule ^(.*) - [E=BASE:%1] 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L] 

另外,不要在任何地方使用相對鏈接! href="img/some-image.jpg"應改爲href="/img/some-image.jpg"

試試看。

+0

感謝您的幫助。我jast添加「/」前面我的鏈接。 –

+0

太棒了!你能標記這個正確的答案嗎? :-) – delboy1978uk

相關問題