简体   繁体   English

.htaccess URL重写导致CSS问题

[英].htaccess URL rewrite causes CSS issue

I have a .htaccess file with the following: 我有一个.htaccess文件,其中包含以下内容:

RewriteEngine On
RewriteRule   ^product/(.+)$   /product.php?name=$1   [L]

This basically looks for "product/" within the URL and redirects to product.php 这基本上是在URL中查找“ product /”,然后重定向到product.php

product.php is in the root folder: eg. product.php在根文件夹中:例如。 mywebsite.com/product.php and when loaded directly looks fine and all CSS works. mywebsite.com/product.php并直接加载时看​​起来不错,并且所有CSS都能正常工作。

However when I go to mywebsite.com/product/example-product the redirect to product.php works, but the CSS is lost (It's in a seperate stylesheet). 但是,当我转到mywebsite.com/product/example-product时 ,可以重定向到product.php,但是CSS丢失了(位于单独的样式表中)。

I do not have a product directory, is this why the CSS won't load? 我没有产品目录,这就是为什么CSS无法加载的原因吗? Is it possible to have directories in the URL yet redirect to a file in the root folder? URL中是否可以包含目录,但仍可以重定向到根文件夹中的文件?

Ideally, I'd like the following: 理想情况下,我想要以下内容:

mywebsite.com/product/example-product mywebsite.com/product/example-product

redirects to 重定向到

mywebsite.com/product.php?name=example-product mywebsite.com/product.php?name=example-product

I hope that makes sense. 我希望这是有道理的。

All you need to do is set a base tag in your HTML head . 您需要做的就是在HTML head设置一个base标记。 For example: 例如:

<base href="http://www.website-example.com">

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

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