Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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 htaccess URL重写试图简化当前URL_Php_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php htaccess URL重写试图简化当前URL

Php htaccess URL重写试图简化当前URL,php,regex,apache,.htaccess,mod-rewrite,Php,Regex,Apache,.htaccess,Mod Rewrite,所以我已经有了一个htaccess文件,它可以正常工作,但是我想把它从一堆参数改为只有一个 因此,我当前的htaccess文件如下所示: Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !/(_modules|css|files|fonts|ico|img|js)/ RewriteRule ^([^/]*|)/?([^/]*|)/?([^/]*|)/?([^/]*|)/?([^/]*|)/?([^

所以我已经有了一个htaccess文件,它可以正常工作,但是我想把它从一堆参数改为只有一个

因此,我当前的htaccess文件如下所示:

Options +FollowSymLinks

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !/(_modules|css|files|fonts|ico|img|js)/
RewriteRule ^([^/]*|)/?([^/]*|)/?([^/]*|)/?([^/]*|)/?([^/]*|)/?([^/]*|)/?([^/]*|)/?([^/]*|) index.php?p1=$1&p2=$2&p3=$3&p4=$4&p5=$5&p6=$6&p7=$7&p8=$8 [L,QSA]
所以我把它改成这样: 选项+FollowSymLinks

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !/(_modules|css|files|fonts|ico|img|js)/
RewriteRule ^([^/]*|)/? index.php?p1=$1 [L,QSA]
但是突然之间,我的css或外部文件都不再工作了

有没有人对如何让htaccess url正常工作,以便它可以从中更改url有什么建议

http://www.example.com/template/index.php?controller=blog/i-am-a-title

http://www.example.com/template/blog/i-am-a-title


而且仍然有它,所以csscss/style.cssworks

尝试将它添加到页面的标题中:

<base href="/template/">


如果您的样式都是相对链接,那么当URL更改为
/template/blog/i-am-a-title
时,相对URL基将更改为
/template/blog/
,您的相对链接将全部中断。

尝试将其添加到页面标题:

<base href="/template/">

如果您的样式都是相对链接,那么当URL更改为
/template/blog/i-am-a-title
时,相对URL基将更改为
/template/blog/
,您的相对链接将全部断开。

您可以尝试以下规则吗:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(index\.php|(_modules|css|files|fonts|ico|img|js)/)
RewriteRule ^([^/]+)/?$ /index.php?p1=$1 [L,QSA]
在css、js、图像文件中使用绝对路径,而不是相对路径。这意味着您必须确保这些文件的路径以
http://
或斜杠开头
/

您可以尝试以下规则:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(index\.php|(_modules|css|files|fonts|ico|img|js)/)
RewriteRule ^([^/]+)/?$ /index.php?p1=$1 [L,QSA]

在css、js、图像文件中使用绝对路径,而不是相对路径。这意味着您必须确保这些文件的路径以
http://
或斜杠开头,如果您有那么复杂的.htaccess文件,只需将所有内容转发到PHP并检查$\u服务器[“REQUEST\u URI”]。并创建类似www.example.com/assets/的东西,将其从重定向中排除。如果您有那么复杂的.htaccess文件,只需将所有内容转发到PHP并检查$\u SERVER[“REQUEST\u URI”]。并创建类似www.example.com/assets/的东西,将其从重定向中排除worse@Aragon0:我不明白你的评论,你能解释一下吗。你的排除条件触发得太频繁了。如果你有一个像/json.html这样的url,你的排除规则与/json.html匹配,并且不将其转发到index.php当我尝试使用此url时,我在该服务器上找不到请求的url模板/blog/I-am-a-title/。上面的.htaccess的位置是什么?它是否放在
blog
目录中?不是很好:会触发ico,js甚至worse@Aragon0:我不明白你的评论,你能解释一下吗。你的排除条件触发得太频繁了。如果你有一个像/json.html这样的url,你的排除规则与/json.html匹配,并且不将其转发到index.php当我尝试使用此url时,我在该服务器上找不到请求的url模板/blog/I-am-a-title/。上面的.htaccess的位置是什么?它是否放在
blog
目录中?您知道我可以使用哪些php来确定基数。因为我在使用它时发现,当我从测试服务器移动到实际服务器时,我必须去更改所有文件。@RobertE.McIntosh尝试类似于
dirname($\u server['PHP\u SELF'))
你知道我可以使用哪些PHP来确定基数吗。因为我正在使用它,发现当我从测试服务器移动到实际服务器时,我必须去更改所有文件。@RobertE.McIntosh尝试类似于
dirname($\u server['PHP\u SELF'))