.htaccess URL 和资源
.htaccess URL and resources
我有下一个url:
www.dude12345.com/section.php?id=5
我想变成这样www.dude12345.com/section/5
我用了下一个代码
Options -MultiViews
RewriteEngine On
# redirect "/section.php?id=xxx" to "/section/xxx"
RewriteCond %{THE_REQUEST} \s/section\.php\?id=([0-9]+)\s [NC]
RewriteRule ^ /section/%1? [R=301,L]
# internally rewrite "/section/xxx" to "/section.php?id=xxx"
RewriteRule ^section/([0-9]+)$ /section.php?id= [L]
它有效..我的 link 它看起来像我想要的那样 (www.dude12345.com/section/5)。
但是我有一个问题,我的资源没有加载好。在控制台中出现类似:"Failed to load resource: the server responded with a status of 404 (Not Found) www.dude12345/section/images/myimg.png " 并且它不正常,需要出现类似 www.dude12345/images/myimg.png 的东西。我不知道如何解决这个问题。
试试这个,对我来说效果很好。
只需确保 mod_rewrite 已启用。
RewriteEngine On
RewriteRule ^/?section/([^/d]+)/?$ section.php?id= [L,QSA]
我有下一个url: www.dude12345.com/section.php?id=5
我想变成这样www.dude12345.com/section/5
我用了下一个代码
Options -MultiViews
RewriteEngine On
# redirect "/section.php?id=xxx" to "/section/xxx"
RewriteCond %{THE_REQUEST} \s/section\.php\?id=([0-9]+)\s [NC]
RewriteRule ^ /section/%1? [R=301,L]
# internally rewrite "/section/xxx" to "/section.php?id=xxx"
RewriteRule ^section/([0-9]+)$ /section.php?id= [L]
它有效..我的 link 它看起来像我想要的那样 (www.dude12345.com/section/5)。 但是我有一个问题,我的资源没有加载好。在控制台中出现类似:"Failed to load resource: the server responded with a status of 404 (Not Found) www.dude12345/section/images/myimg.png " 并且它不正常,需要出现类似 www.dude12345/images/myimg.png 的东西。我不知道如何解决这个问题。
试试这个,对我来说效果很好。 只需确保 mod_rewrite 已启用。
RewriteEngine On
RewriteRule ^/?section/([^/d]+)/?$ section.php?id= [L,QSA]