.htaccess 核心PHP上的URL重写

.htaccess 核心PHP上的URL重写,.htaccess,redirect,mod-rewrite,url-rewriting,.htaccess,Redirect,Mod Rewrite,Url Rewriting,我想从中重写URL example.com/file.php?id=yes 到 该网站位于核心PHP上 我在.htaccess Options +FollowSymLinks RewriteEngine On RewriteRule ^([0-9]+).html /abc.php?id=$1 [QSA,L] 是的,我有,现在我只想将example.com/file.php?id=Yes重定向到example.com/file.php/Yes 为了保留SEO,更改URL结构后,您可以在.hta

我想从中重写URL

example.com/file.php?id=yes

该网站位于核心PHP上

我在
.htaccess

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([0-9]+).html /abc.php?id=$1 [QSA,L]
是的,我有,现在我只想将
example.com/file.php?id=Yes
重定向到
example.com/file.php/Yes

为了保留SEO,更改URL结构后,您可以在
.htaccess
文件顶部执行如下外部重定向:

Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{QUERY_STRING} ^id=(\w+)
RewriteRule ^file\.php$ /$0/%1 [QSD,R=301,L]
$0
反向引用包含来自
重写规则
模式(即
file.php
)的完全匹配。而
%1
反向引用(注意
%
)包含前面模式中
id
URL参数的值

QSD
标志是从重定向请求中丢弃原始查询字符串所必需的

注意:您应该首先使用302(临时)重定向进行测试,以避免潜在的缓存问题

旁白:


事实上,我想这样做是因为化妆品的原因,也使这个搜索引擎优化友好

尽管如此,这两个URL在SEO方面并没有什么区别。事实上,仅仅改变URL结构,你可能会对SEO产生短期的负面影响

这似乎做了相反的事情,与你的预期行为完全不同


它会在内部将
/0123456789.html?foo=1
格式的URL重写(而不是“重定向”)为
/abc.php?id=0123456789&foo=1
在您看来,
^([0-9]+).html
在这里可能匹配什么?另外,为什么要将URL从
/file.php?id=yes
重写为
/file.php/yes>?这是出于“装饰性”的原因,还是您正试图解决一些潜在的技术问题?(因为,从表面上看,这在实践中没有真正意义。)实际上,我想做这件事是因为表面上的原因,同时也做了这个SEOfriendly@MrWhite,是的,我有,现在我只想将example.com/file.php?id=Yes重定向到example.com/file.php/yesHow你开始做这个了吗?
Options +FollowSymLinks -MultiViews
RewriteEngine On

RewriteCond %{QUERY_STRING} ^id=(\w+)
RewriteRule ^file\.php$ /$0/%1 [QSD,R=301,L]
RewriteRule ^([0-9]+).html /abc.php?id=$1 [QSA,L]