Wordpress htacces重写url时使用了&;id';s
我遇到了一个困难的情况,在这种情况下,我需要将带有“?”和“id”的url重写为一个seo友好的url 以下是实际的URLWordpress htacces重写url时使用了&;id';s,wordpress,apache,.htaccess,url,seo,Wordpress,Apache,.htaccess,Url,Seo,我遇到了一个困难的情况,在这种情况下,我需要将带有“?”和“id”的url重写为一个seo友好的url 以下是实际的URL 我需要把它改成这样。 我的htacces代码 <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^services/car-dealers.html services.html?sr=1 [L] RewriteRule ^services/r
我需要把它改成这样。
我的htacces代码
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^services/car-dealers.html services.html?sr=1 [L]
RewriteRule ^services/restaurent.html services.html?sr=2 [L]
RewriteRule ^services/nonprofit.html services.html?sr=3 [L]
RewriteRule ^services/school.html services.html?sr=4 [L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
重新启动发动机
重写规则^services/car-derals.html services.html?sr=1[L]
重写规则^services/restaurent.html services.html?sr=2[L]
重写规则^services/unprivate.html services.html?sr=3[L]
重写规则^services/school.html services.html?sr=4[L]
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
我使用WordPress作为CMS。有什么可能性吗?试试这个:
RewriteEngine on
RewriteRule ^services/car-dealers services.html?sr=1 [NC]
RewriteRule ^services/restaurent services.html?sr=2 [NC]
RewriteRule ^services/nonprofit services.html?sr=3 [NC]
RewriteRule ^services/school services.html?sr=4 [NC]
然后访问这里有一个解决方案,可以实现这一点,对于案例sr=1,对其他URL也一样
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{QUERY_STRING} ^sr=1$
RewriteRule ^services\.html$ /services/car-dealers.html [NC,R=301,L]
RewriteRule ^services/car-dealers services.html?sr=1 [L,NC]
为了避免对每个可以使用的url重复代码,首先创建一个包含键值对的txt文件,如下所示:
car-dealers 1
restaurent 2
nonprofit 3
school 4
1 car-dealers
2 restaurent
3 nonprofit
4 school
然后在您的htaccess中:
RewriteMap name2id txt:/etc/apache2/name2idmap.txt
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{QUERY_STRING} ^sr=([0-9]+)$
RewriteRule ^services\.html$ /services/${name2id:%1} [NC,R=301,L]
RewriteRule ^services/(.+?)\.html services.html?sr=${name2id:$1} [L,NC]
谢谢你的回答。但这对我不起作用。不重定向。在RewriteRule^services/sample services.html上使用以下htacces代码重写引擎?sr=1[NC]重定向不在问题范围内。如果你看看,你会发现它是有效的。只需将所有链接更改为新的干净链接:)