【问题标题】:Renaming inner page urls to seo friendly urls using .htaccess使用 .htaccess 将内页 url 重命名为 seo 友好的 url
【发布时间】:2013-02-09 14:38:33
【问题描述】:

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

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

如果您向我展示 4 或 5 个使用 .htaccess 的 URL 重命名技术,我将使用剩余的 URL。我接到了这个任务,但我做不到。

【问题讨论】:

  • 嗯,到目前为止你尝试了什么?您没有发布您当前的设置,因此我们无法指出问题所在。我希望你不要指望这里有人为你做作业......特别是因为这是重写 mod 的基本用法,你需要的一切都有很好的文档和解释,包括好的基本示例。

标签: .htaccess url-rewriting seo


【解决方案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

对于 page 重定向,您可以使用以下方法(地图文件会有所不同以及 RewriteRule 表达式)

在进行任何工作之前,我建议您先阅读RewriteMap documentation,以便了解该工具,即它的配置和用法。

我希望这将是您任务的好方向。

【讨论】:

    【解决方案2】:
    <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

    【讨论】:

      猜你喜欢
      • 2021-07-06
      • 2021-07-23
      • 1970-01-01
      • 2011-05-29
      • 2013-01-22
      • 2011-12-28
      • 1970-01-01
      • 1970-01-01
      • 2018-04-28
      相关资源
      最近更新 更多