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 在htaccess中更改后,每次单击都会修改URL_Php_.htaccess_Url - Fatal编程技术网

Php 在htaccess中更改后,每次单击都会修改URL

Php 在htaccess中更改后,每次单击都会修改URL,php,.htaccess,url,Php,.htaccess,Url,我正在修改我的php脚本以便于搜索引擎优化 当我第一次单击test.php页面中的链接时,它在url中显示为htp://example/test/first 工作很好。 当第二次点击url成为htp://example/test/test/first.test 文件夹正在继续添加到URL中 如何看待这个问题 ##test.php <html> <head></head> <body> <a href='test/first'>test

我正在修改我的php脚本以便于搜索引擎优化

当我第一次单击test.php页面中的链接时,它在url中显示为htp://example/test/first 工作很好。 当第二次点击url成为htp://example/test/test/first.test 文件夹正在继续添加到URL中

如何看待这个问题

##test.php
<html>
<head></head>
<body>
<a  href='test/first'>testing</a> <br>
<body> 
</html>

##.htaccess
RewriteEngine On
RewriteBase 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
RewriteRule ^test/(.+)  /test.php?$1 [L]
DirectoryIndex test.php
##test.php

##.htaccess 重新启动发动机 重写基 重写cond%{REQUEST_FILENAME}-D 重写cond%{REQUEST_URI}/$ 重写规则(.*)/$1[R=301] 重写规则^test/(.+)/test.php?$1[L] DirectoryIndex test.php
解决这个问题的几种可能性

1) 在URL前面斜杠

 <a  href='/test/first'>testing</a>

只有当您的网站不包含在web空间的子目录中时,它才会起作用

2) 绝对URL

 <a  href='http://www.example.com/test/first'>testing</a>

您可以将其保存在配置文件或其他文件(baseUrl any?)中,并像下面这样动态地将其附加到链接中

 <a  href='<?=$cfg->baseUrl?>/test/first'>testing</a>
 <base href="http://example.com/">

3) HTML

像这样在头部标签上设置一个底部

 <a  href='<?=$cfg->baseUrl?>/test/first'>testing</a>
 <base href="http://example.com/">


哪些路径可能会中断站点上的其他路径,如图像路径和CSS路径

您单击的链接的外观如何?