【问题标题】:Create a permalink with htaccess使用 htaccess 创建永久链接
【发布时间】:2015-11-18 19:54:15
【问题描述】:

我可以得到帮助吗:

我在谷歌网站管理员工具上看到这样的链接断开: test.php?t=test%20title

test.php 页面被删除,现在我使用 index.php 而不是 test.php

所以我需要用 htaccess 再次重写 url。我该怎么做?

http://www.domain.com/test.php?t=test%20title 链接更改为 http://www.domain.com/t/test-title/ 或者 http://www.domain.com/index.php?t=test%20title

我确实尝试了这些选项,但没有奏效:

ReWriteRule ^test.php?t=(.*)$ index.php?t=$1
ReWriteRule ^test.php?t=([0-9a-z]+)$ index.php?t=$1
ReWriteRule ^test\.php\?t=(.*)$ index.php?t=$1
ReWriteRule ^test\.php\?t=([0-9a-z]+)$ index.php?t=$1

可以为此使用 htaccess 创建永久链接吗? http://www.domain.com/t/test-title/

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    查询字符串不是 RewriteRule 指令匹配的一部分,使用 %{THE_REQUEST} 变量来匹配查询字符串。

    在你的 htaccess 中试试这个:

    RewriteEngine on
    
    RewriteCond %{THE_REQUEST} /index\.php\?t=([^\s]+)\s*([^\s&]+)\sHTTP/1.1 [NC]
    RewriteRule ^ /t/%1-%2? [NC,L,R]
    RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^t/([^-]+)-([^/]+)/?$ /index.php?t=$1%20$2 [NC,L]
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-21
    • 1970-01-01
    相关资源
    最近更新 更多