php - .htaccess 文件中的 url 重写问题

标签 php mysql .htaccess

这是我的问题

在我的网站基础 url 中重定向到一个内部文件夹

eg: http://example.com/ 

     to 

http://onlinevyapari.com/business/ by using this code in .htaccess file 
RewriteRule ^(/)?$ /business/index.php [L]

现在我想为同一个网站使用搜索引擎友好的 url 我的查询是这样的 http://example.com/business-details.php?id=106

但我想保留我的网址
http://example.com/business-details/106

我已经用不同的方式做了,就像下面这样

RewriteEngine on
RewriteRule business-details/id/(.*)/ business-details.php?id=$1
RewriteRule business-details/id/(.*) business-details.php?id=$1

它发生了,但是 css 没有正确加载

如果有人提供帮助,我将非常感激。 谢谢

最佳答案

你的规则是这样的:

RewriteEngine on

RewriteRule ^(/)?$ business/index.php [L]

RewriteRule ^business-details/(\d+)/?$ business-details.php?id=$1 [L,QSA,NC]

要解决 css/js/image 路径问题,只需在 css、js、图像文件中使用绝对路径,而不是相对路径。这意味着您必须确保这些文件的路径以 http:// 开头或斜线 / .

或者您可以尝试在页面的 HTML header 中添加:<base href="/" />这样每个相对 URL 都是从该 URL 而不是当前 URL 解析的。

关于php - .htaccess 文件中的 url 重写问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27190101/

相关文章:

php - 从我的数据库中获取内容到 php 中的表单时遇到问题

php - Symfony3如何在数据库中存储用户角色

mysql - VB NET - 查询 Mysql - 在哪里\

php - 保存时,如何修复 "set"方法来更新条目。在 Controller 上添加表单验证后

apache - .htaccess 中的 SSLCipherSuite 未生效

wordpress - WordPress 的 .htaccess 和 SEO 是如何构建的?

php - 如何加载多级关系?

php - 为什么我的服务器将添加值视为mysql_query中的identifier_link?

php - 服务器更改后 .htaccess 中出现奇怪的问题

php - 如何在 mysql 中比较/匹配两个逗号分隔值