Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 重写规则以删除漂亮URL的无关URL部分 背景_Php_.htaccess_Mod Rewrite_Pretty Urls - Fatal编程技术网

Php 重写规则以删除漂亮URL的无关URL部分 背景

Php 重写规则以删除漂亮URL的无关URL部分 背景,php,.htaccess,mod-rewrite,pretty-urls,Php,.htaccess,Mod Rewrite,Pretty Urls,尝试使用Apache的mod rewrite和PHP重新创建StackOverflow风格的漂亮URL 问题 这非常有效: <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ([0-9]+)$ index.php?id=$1 [L] </IfModule> 名录 脚本(index.php)的目录结构类似于: htdocs/home/script htdocs/home/script/.htaccess

尝试使用Apache的mod rewrite和PHP重新创建StackOverflow风格的漂亮URL

问题 这非常有效:

<IfModule mod_rewrite.c>
  RewriteEngine on

  RewriteRule ([0-9]+)$ index.php?id=$1 [L]
</IfModule>
名录 脚本(index.php)的目录结构类似于:

htdocs/home/script
htdocs/home/script/.htaccess
htdocs/home/script/index.php
htdocs/home/script/css
htdocs/home/script/images
问题: 如何使用mod rewrite告诉Apache在提供文件时使用“script”目录,而不是附加到URL的任何子目录

换句话说,你将如何使用mod rewrite删除URL中的“seo文本”部分,并(1)确保它反映实际标题[来源于数据库];(2) 将浏览器重定向到新URL[如有必要];和(3)告诉Apache忽略URL中ID之外的所有路径

我宁愿不要在CSS中使用绝对路径

谢谢大家!

使用了洛根的建议:

<base href="/home/script/" target="_self" />


由于一个bug,这不适用于IE8。

使用
base
HTML标记(即使动态更新)会是一个选项吗?()您不能通过添加像这样的正斜杠将样式表直接设置为使用根目录吗
/css/theme.css
?开发环境的根目录与生产环境的根目录不同。在开发中是
/home/account/htdocs/site/root
,而在生产中是
/home/account/site/htdocs/root
,这就是绝对路径无法工作的原因(如果没有一些我宁愿避免的努力)。
<base href="/home/script/" target="_self" />