2017-04-24 142 views
1

我在PHP应用程序,它会生成以下链接PHP URL重写CSS不工作

http://localhost/24_2_april/video-library/2/Programming-Language

但自从我使用htaccess的,使我的URL干净,工作自那时以来,CSS和JS没有工作。现在我知道我可以给CSS的绝对路径,但我不认为这是正确的做法,我也尝试使用RewriteCond %{REQUEST_FILENAME} !-f,但目前为止没有运气....

这是我的htaccess代码至今。

Options +FollowSymLinks 
RewriteEngine On 
RewriteRule ^video-library/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ var/www/html/24_2_april/video.php?cat_id=$1&category=$2 [L] 
RewriteRule ^video-library/([A-Za-z0-9-]+)/?$ var/www/html/24_2_april/search_results.php?cat_id=$1 [L] 
+0

什么是你的CSS和JS文件的路径? – Thakkie

+0

它只在我的项目文件夹中。 –

回答

0

在我看来,要走的路是使用RewriteCond。这些重写规则只有在没有可用的实际文件时才会执行。如果你的文件是符号链接,你可能需要添加RewriteCond %{REQUEST_FILENAME}% !-l

Options +FollowSymLinks 
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME}% !-f 
RewriteCond %{REQUEST_FILENAME}% !-d 
RewriteRule ^video-library/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ var/www/html/24_2_april/video.php?cat_id=$1&category=$2 [L] 

RewriteCond %{REQUEST_FILENAME}% !-f 
RewriteCond %{REQUEST_FILENAME}% !-d 
RewriteRule ^video-library/([A-Za-z0-9-]+)/?$ var/www/html/24_2_april/search_results.php?cat_id=$1 [L] 
0

试试这个

Options +FollowSymLinks 
RewriteEngine On 

RewriteRule ^video-library/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ http://localhost/24_2_april/video.php?cat_id=$1&category=$2 [L] 
RewriteRule ^video-library/([A-Za-z0-9-]+)/?$ http://localhost/24_2_april/search_results.php?cat_id=$1 [L] 
+0

对不起兄弟,但那并没有奏效。该页面只是加载没有CSS和JS。 –

+0

现在CSS正在工作,但重写没有正确完成。 –

+0

将htaccess更新为RewriteBase/24_2_april /,然后从规则中删除完整的URL。例如/search_result.php,/video.php –