使用.htaccess将内页网址重命名为seo友好网址

时间:2013-02-24 09:12:49

标签: .htaccess url-rewriting seo

我想将以下网址重命名为SEO友好网址。

Change the following URL : http://www.peacockgirls.com/index.php?page=1 into http://www.peacockgirls.com
Change the following URL : http://www.peacockgirls.com/index.php?page=2 into http://www.peacockgirls.com/greece-escort
Change the following URL : http://www.peacockgirls.com/index.php?page=3 into http://www.peacockgirls.com/athens-escort
Change the following URL : http://www.peacockgirls.com/index.php?page=4 into http://www.peacockgirls.com/bookings
Change the following URL : http://www.peacockgirls.com/index.php?page=5 into http://www.peacockgirls.com/jobs
Change the following URL : http://www.peacockgirls.com/index.php?page=6 into http://www.peacockgirls.com/contact-us
Change the following URL : http://www.peacockgirls.com/index.php?page=24 into http://www.peacockgirls.com/articles
Change the following URL : http://www.peacockgirls.com/index.php?page=7 into http://www.peacockgirls.com/links
Change the following URL : http://www.peacockgirls.com/index.php?profile=22 into http://www.peacockgirls.com/profile/aleena
Change the following URL : http://www.peacockgirls.com/index.php?profile=40 into http://www.peacockgirls.com/profile/fabiana
Change the following URL : http://www.peacockgirls.com/index.php?profile=48 into http://www.peacockgirls.com/profile/sabrina
Change the following URL : http://www.peacockgirls.com/index.php?profile=69 into http://www.peacockgirls.com/profile/suzanna
Change the following URL : http://www.peacockgirls.com/index.php?profile=63 into http://www.peacockgirls.com/profile/anna
Change the following URL : http://www.peacockgirls.com/index.php?profile=70 into http://www.peacockgirls.com/profile/sam
Change the following URL : http://www.peacockgirls.com/index.php?profile=61 into http://www.peacockgirls.com/profile/Larissa&Samantha
Change the following URL : http://www.peacockgirls.com/index.php?profile=54 into http://www.peacockgirls.com/profile/McKenzie
Change the following URL : http://www.peacockgirls.com/index.php?profile=29 into http://www.peacockgirls.com/profile/valery

如果您使用.htaccess向我显示4或5个网址重命名技术,我将继续使用其他网址。我接受了这项任务,但不能这样做。

2 个答案:

答案 0 :(得分:1)

有了这样的任务,我会选择RewriteMap

您可以使用两个单独的地图文本文件(以便更好地管理文件):一个用于配置文件,一个用于页面(任何新文件用于其他类型的重写)。

您的.htaccess可以这样设置:

RewriteMap userid txt:/etc/apache2/useridmap.txt
RewriteRule ^/index.php?page=(.+) /profile/${userid:$1} [L,R=301]

地图文本文件格式如下:

# Comment line
MatchingKey SubstValue
MatchingKey SubstValue # comment

在您的情况下,配置文件文本文件可能如下所示:

22 aleena
40 fabiana
# more mappings

对于页面重定向,您可以使用以下方法(地图文件将与RewriteRule表达式不同)

在开始任何工作之前,我建议您首先浏览RewriteMap documentation,以便了解该工具,即其配置和使用情况。

我希望这对你的任务来说是个好方向。

答案 1 :(得分:1)

<IfModule mod_rewrite.c> 
   RewriteEngine On
   RewriteRule %{REQUEST_FILENAME} !-f
   RewriteRule %{REQUEST_FILENAME} !-d
   RewriteBase /

   RewriteRule ^/greece-escort/?$ /index.php?page=2 [NC,L]
   RewriteRule ^/athens-escort/?$ /index.php?page=3 [NC,L]
   RewriteRule ^/bookings/?$ /index.php?page=4 [NC,L]
   RewriteRule ^/jobs/?$ /index.php?page=5 [NC,L]
   RewriteRule ^/contact-us/?$ /index.php?page=6 [NC,L]
   RewriteRule ^/articles/?$ /index.php?page=24 [NC,L]
   RewriteRule ^/links/?$ /index.php?page=7 [NC,L]
   RewriteRule ^/profile/aleena/?$ /index.php?profile=22 [NC,L]
   RewriteRule ^/profile/fabiana/?$ /index.php?profile=40 [NC,L]
   RewriteRule ^/profile/sabrina/?$ /index.php?profile=48 [NC,L]
   RewriteRule ^/profile/suzanna/?$ /index.php?profile=69 [NC,L]
   RewriteRule ^/profile/anna/?$ /index.php?profile=63 [NC,L]
   RewriteRule ^/profile/sam/?$ /index.php?profile=70 [NC,L]
   RewriteRule ^/profile/Larissa&Samantha/?$ /index.php?profile=61 [NC,L]
   RewriteRule ^/profile/McKenzie/?$ /index.php?profile=54 [NC,L]
   RewriteRule ^/profile/valery/?$ /index.php?profile=29 [NC,L]
</IfModule>

的.htaccess

相关问题