简体   繁体   English

如何使用 .htaccess 进行 url 重写?

[英]How to use .htaccess for url rewrite?

在此处输入图片说明 I used .htaccess for url rewrite.These code used.我使用 .htaccess 进行 url 重写。使用了这些代码。

RewriteRule  ^products/([0-9]+)/?$    search.php?srhCat=$1    [NC,L]    # Handle product requests

These rule is ok to call php file.But other css,image path is wrong.这些规则调用php文件是可以的。但是其他的css,图片路径是错误的。 How to solve these error.如何解决这些错误。

Based on your URL rewrite, the path now changes to根据您的 URL 重写,路径现在更改为

http://localhost/superpages/products/4 http://localhost/superpages/products/4

It will then attempt to load your assets on:然后它会尝试将您的资产加载到:

http://localhost/superpages/products/4/js/sample.js http://localhost/superpages/products/4/css/sample.css http://localhost/superpages/products/4/images/sample.jpg http://localhost/superpages/products/4/js/sample.js http://localhost/superpages/products/4/css/sample.css http://localhost/superpages/products/4/images/sample。 jpg

You may check your browser's debug console to check where those assets are being loaded.您可以检查浏览器的调试控制台以检查这些资产的加载位置。 You may expect to see a 404 error on the said assets.您可能希望在上述资产上看到 404 错误。 You may fix this by providing the document root path preceding the asset file.您可以通过在资产文件之前提供文档根路径来解决此问题。

In your html if you are using relative paths for the js, images, css than their paths should begin with / :在你的 html 中,如果你使用的是 js、图像、css 的相对路径,那么它们的路径应该以/开头:

 <img src="/<path to the image>">

If you add the html code of the page or the failed requests for css and image files it would help.如果您添加页面的 html 代码或对 css 和图像文件的失败请求,它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM