【发布时间】:2017-08-13 00:45:06
【问题描述】:
我在尝试在不更改其内容的情况下重写 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 直到现在
【问题讨论】:
-
认为你需要更换你的 RewriteRule。首先是模式,然后是替换,例如像这样的东西(尽管不要引用我的话):
RewriteRule ^/audit-seo/ /audit-seo/frtcrwl/health_check/report/(.*)$ /$1 [L,NC,R=301,NE]:addedbytes.com/articles/for-beginners/… -
@justbaron 不,它不起作用。不改变 url,只改变路径,现在抛出 404
-
手动输入时,女巫路径有效吗?
http://fortin.agency/audit-seo/frtcrwl/health_check/report/578/leasingautomobile.ro或http://fortin.agency/audit-seo/578/leasingautomobile.ro? -
是的,但是没有任何重写规则,哪个有效?
标签: php apache .htaccess url mod-rewrite