Php Htaccess在浏览器中重写url,但不影响页面(仅更改外观url)

Php Htaccess在浏览器中重写url,但不影响页面(仅更改外观url),php,apache,.htaccess,url,mod-rewrite,Php,Apache,.htaccess,Url,Mod Rewrite,我正在努力解决一个问题,试图重写一个url而不改变它的内容 我想在浏览器url中显示不同的url,但内容仍然相同 我的url是http://fortin.agency/audit-seo/frtcrwl/health_check/report/578/leasingautomobile.ro 我想把它改成http://fortin.agency/audit-seo/578/leasingautomobile.ro 我所做的: Options +FollowSymlinks RewriteEngi

我正在努力解决一个问题,试图重写一个url而不改变它的内容

我想在浏览器url中显示不同的url,但内容仍然相同

我的url是
http://fortin.agency/audit-seo/frtcrwl/health_check/report/578/leasingautomobile.ro

我想把它改成
http://fortin.agency/audit-seo/578/leasingautomobile.ro

我所做的:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^frtcrwl/health_check/report/(.*)$ /$1 [L,NC,R=301,NE]
不起作用。。。有什么帮助吗

编辑

url中的578是动态的,也是“leasingautomobile.ro”

编辑#2

最终代码:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_URI} ^/(audit-seo)/frtcrwl/health_check/report/(.+)$ [NC]
RewriteRule ^ /%1/%2 [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L] 

仍然没有按预期工作,因为它抛出了错误404。这条路能保持不变吗?因为浏览器链接中的url现在是完美的。感谢@anubhava直到现在

将您的规则更改为此,并在
frtcrwl/.htaccess内重新测试

Options +FollowSymlinks
RewriteEngine on
RewriteBase /audit-seo/frtcrwl/

RewriteCond %{THE_REQUEST} \s/+(audit-seo/frtcrwl)/health_check/report/(\S+) [NC]
RewriteRule ^ /%1/%2 [L,R=301,NE]

RewriteRule ^\d+/[^/]+/?$ index.php?/health_check/report/$0 [L,NC,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L,QSA]

如果您想访问
http://fortin.agency/audit-seo/frtcrwl/health_check/report/578/leasingautomobile.ro
from
http://fortin.agency/audit-seo/578/leasingautomobile.ro
您可以使用以下规则:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^audit-seo/(.+)$ audit-seo/frtcrwl/health_check/report/$1 [L,NC]

你认为你需要改变你的规则。首先是模式,然后是替换,例如类似这样的东西(不要引用我的话):
RewriteRule^/audit-seo//audit-seo/frtcrwl/health\u-check/report/(.*)$/$1[L,NC,R=301,NE]
:@justbaron-no,它不起作用。不更改url,只更改路径,当您手动输入时,它会抛出404,巫婆路径正在工作<代码>http://fortin.agency/audit-seo/frtcrwl/health_check/report/578/leasingautomobile.ro
http://fortin.agency/audit-seo/578/leasingautomobile.ro
?是的,但是没有任何重写规则,一个在哪里工作?非常感谢。你就像htaccess的上帝:你的代码工作正常,但我发现使用RewriteCond%{REQUEST_FILENAME}有点奇怪-f RewriteCond%{REQUEST_FILENAME}-重写规则。*index.php?/$0[PT,L]由于这些选项覆盖了您的代码,所以它似乎不起作用。它能被修复成我所期望的并保留选项吗?好的,我把它放在我的代码上,它现在工作了,但它似乎不是一个有效的页面(404)。有没有办法保持当前目录路径但显示不同的url?有没有办法,清除我的浏览器缓存并使用您的代码,出现404错误,浏览器url中的url不再更改:(好的,现在试试我的更新答案。这是位于
audit seo/
目录中的.htaccess吗?谢谢你的回答,但是你的代码不起作用……它不会改变url。你能检查anubhava对我的评论吗?他的代码会改变url,但也会改变路径。我不需要这样做,因为它会抛出404不,它会改变。)仅路径,加载路径,但url保持不变。我更改了答案。您现在可以访问您的页面
http://fortin.agency/audit-seo/frtcrwl/health_check/report/578/leasingautomobile.ro
from
http://fortin.agency/audit-seo/578/leasingautomobile.ro
。仍然404使用最新的源代码和链接: