我想在有人调用像example.com/page/3fssdfs这样的网址时重定向网址,它会像页面一样吗?id = 3fssdfs为此我使用了以下htaccess代码。
RewriteRule ^page/([A-Za-z0-9-]+)/?$ page.php?id=$1
因此,当有人访问example.com/page/3fssdfs时,页面加载正常。但是,CSS和图像文件不会加载。当我检查控制台时,它们看起来像这样,
GET http://example.com/page/assets/css/index.css 404 (Not Found)
css文件的存储方式与example.com/assets
类似那么我该如何修复错误呢?感谢
UPDATE这里是完整的.htaccess文件
RewriteEngine on
RewriteBase /
#if the file does NOT exist (! means NOT, and -f means file exists)
RewriteCond %{REQUEST_FILENAME} !-f
#if the directory does NOT exit (-d stands for directory exists)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/([A-Za-z0-9-]+)/?$ page.php?id=$1
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^\.]+)$ $1.html [NC]'
答案 0 :(得分:1)
添加重写条件:
#if the file does NOT exist (! means NOT, and -f means file exists)
RewriteCond %{REQUEST_FILENAME} !-f
#if the directory does NOT exit (-d stands for directory exists)
RewriteCond %{REQUEST_FILENAME} !-d`
在重写规则之前。
如果上述两项成立,您的规则将被重写;如果没有,将不会有任何重写,您将能够访问内容文件。