简体   繁体   中英

Using mod_rewrite to Convert Dynamic URLs to SEO Friendly URLs ??

I am not a PHP developer and I have been asked to perform some SEO . Here Is My .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

I'm trying to rewrite my URLs to be more SEO friendly, and I'm doing this in my .htaccess file using the following code:

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

Last Code not working With my site :S i don't Know !! Help Please http://www.afrogfx.com/index

URL to Convert

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

OR

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

Last Code not working With my site :S i don't Know

You can't match against the query string in a RewriteRule , you also don't want to blindly rewrite the URI since the rule right before it does that, and you'll just cause a redirect loop. Change your second rule to:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM