Php 友好URL保留在URL的旧部分

Php 友好URL保留在URL的旧部分,php,.htaccess,Php,.htaccess,我开始使用友好的URL,但我有两个问题 我有一个指向www.mywebsite.com/articles.php/321312/some-text-here的链接 当我点击这个链接时,在下一页上,我的所有链接都会保留一部分url 例如,可单击的徽标图像指向www.mywebsite.com/articles/321312/index.php,而不是www.mywebsite.com/index.php 另一个问题是articles.php仅适用于.php扩展名 我在这里的权限 <IfMod

我开始使用友好的URL,但我有两个问题

我有一个指向www.mywebsite.com/articles.php/321312/some-text-here的链接

当我点击这个链接时,在下一页上,我的所有链接都会保留一部分url

例如,可单击的徽标图像指向www.mywebsite.com/articles/321312/index.php,而不是www.mywebsite.com/index.php

另一个问题是articles.php仅适用于.php扩展名

我在这里的权限

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME}\.php -f
  RewriteRule ^ / [R=301,L]
  RedirectMatch ^/$ /articles/
  RewriteRule ^([^/\.]+)/?$ $1.php  [L,QSA]

  RewriteRule ^articles/([a-z0-9-]+)/([0-9]+)/?$ /articles.php?id=$2&desc=$1 [NC]
</IfModule>

重新启动发动机
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}\.php-f
重写规则^/[R=301,L]
重定向匹配^/$/文章/
重写规则^([^/\.]+)/?$$1.php[L,QSA]
重写规则^articles/([a-z0-9-]+)/([0-9]+)/?$/articles.php?id=$2&desc=$1[NC]

提前感谢。

用以下代码替换.htaccess代码:

RewriteEngine On

RewriteRule ^$ /articles/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/.]+)/?$ $1.php [L]

RewriteRule ^articles/([a-z0-9-]+)/([0-9]+)/?$ articles.php?id=$2&desc=$1 [L,QSA,NC]
您还必须在页面HTML的
标记下方添加以下内容:

<base href="/" />


因此,每个相对URL都是从该基本URL解析的,而不是从当前页面的URL解析的。

除了PHP扩展之外,它可以部分工作,但很好。当我在没有.phpca的情况下键入时,它会重定向到404。你能注释掉
RewriteCond%{REQUEST\u FILENAME}\.php-f
行吗?你试过了吗?