使用mod_rewrite将动态URL转换为SEO友好的URL?



我不是PHP开发人员,我被要求执行一些SEO。这是我的 .htaccess

    RewriteEngine On
    RewriteBase /
    RewriteRule [_ ] space.cgi [L]
    ErrorDocument 404 /errors/404.php 
    ErrorDocument 400 /errors/badrequest.php
    ErrorDocument 401 /errors/authreqd.php
    ErrorDocument 403 /errors/forbid.php
    ErrorDocument 500 /errors/serverr.php 
    ErrorDocument 503 /errors/ServiceUnavailable.php 
    RewriteEngine On 
    RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^Bot mailto:craftbot@yahoo.com [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^Custo [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^HMView [OR] 
    RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR] 
    RewriteCond %{HTTP_USER_AGENT} ^Image Stripper [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^Image Sucker [OR] 
    RewriteCond %{HTTP_USER_AGENT} Indy Library [NC,OR] 
    RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^Internet Ninja [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^JOC Web Spider [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^larbin [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^Website Quester [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^Wget [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^Widow [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^Xaldon WebSpider [OR] 
    RewriteCond %{HTTP_USER_AGENT} ^Zeus 
    RewriteRule ^.* - [F,L]
    RewriteRule rss.xml rss.php [QSA,L]
    RewriteEngine on
    RewriteRule ^index.htm$ index.php
    RewriteRule ^search.htm$ search.php
    RewriteRule ^about.htm$ about.php
    RewriteRule ^contacts.htm$ contacts.php
    RewriteRule ^gallery.htm$ gallery.php
    RewriteRule readmore.htm$ readmore.php
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule .* $0.php
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.htm -f
    RewriteRule .* $0.htm

我正在尝试重写我的 URL 以使其对 SEO 更友好,并且我使用以下代码在我的 .htaccess 文件中执行此操作:

RewriteEngine On      
RewriteRule blog/(.*)/$ readmore.php?&postid=$1 [NC]      
RewriteRule ^/*(.+/)?([^.]*[^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]

最后一个代码在我的网站上不起作用:我不知道!!请帮忙http://www.afrogfx.com/index

要转换的网址

 http://www.afrogfx.com/readmore?postid=62&categories=6&catid=6#.UG3ZoK5adS8

http://www.afrogfx.com/readmore?postid=62

最后一个代码在我的网站上不起作用:我不知道

您无法与RewriteRule中的查询字符串匹配,您也不想盲目重写 URI,因为规则就在它这样做之前,您只会导致重定向循环。将第二条规则更改为:

RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD) /readmore.php?
RewriteCond %{QUERY_STRING} postid=([^&]+)
RewriteRule ^ /blog/%1/ [L,R=301]

最新更新