如何更改url php脚本htaccess方法

时间:2016-04-16 18:00:46

标签: php .htaccess url-rewriting

如何更改此网址

http://domain.com/search/song

http://domain.com/search/song.html

.htaccess文件

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php?/$1 [QSA,L] 

1 个答案:

答案 0 :(得分:2)

尝试添加字符串

RewriteRule ^(/search/song)$ $1.html [L,R=301]

RewriteEngine On

之后

如果这不起作用,请尝试将其放入:

RedirectMatch 301 ^(/search/song)$ $1.html

这应该完美无缺。