我已经用我的.htaccess文件中加入 WWW。
来索引网址,删除的.php
和删除?ID =
从网址。
这是原始地址:
www.site.com/article.php?id=12&title=title-text
URL以的.htaccess code
www.site.com/article/12
这code已经删除&放大器;标题=标题文字
从网址
如何删除&放大器;标题=
没有标题文字
?像这样的:
www.site.com/article/12/title-text
.htaccess文件
选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{HTTP_HOST} ^ ifeelvideos.com [NC]
重写规则^(。*)$ http://www.ifeelvideos.com/$1 [L,R = 301]
#要外部重定向/dir/foo.php?id=123到/ DIR /富
?的RewriteCond%{THE_REQUEST} ^ GET S([^] +) PHP ID =([^&放大器; S] +)[NC]
重写规则^%1 /%2? [R,L]
#在内部前进/ DIR /富/ 12 /dir/foo.php?id=12
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME -f .PHP
重写规则^(。+?)/([^ /] +)/ $ $ 1.PHP?ID = $ 2 [L,QSA]
#要外部重定向/dir/foo.php到/ DIR /富
的RewriteCond%{THE_REQUEST} ^ GET S([^。] +)。PHP S [NC]
重写规则^%1 [R,L]
#在内部前进/ DIR /富到/dir/foo.php
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME -f .PHP
的RewriteCond%{QUERY_STRING} ^ $
重写规则^(。*?)/?$ $ 1.PHP [L]
#Alternate默认的索引页
DirectoryIndex的first.html的index.htm index.html的index.php文件
解决方案
我假设article.php实际上并不需要的标题来操作,只有身份证。您只能将标题添加到URL如果标题中的URL摆在首位的存在。你可以离开了第二条规则,如果标题
总是在URL中。
#如果需要外部重定向/dir/foo.php?id=123&title=456到/ DIR /四百五十六分之一百二十三
?的RewriteCond%{THE_REQUEST} ^ GET S([^] +) PHP ID =([^&功放;] +)及标题=([^&放大器; S] +)[NC]
重写规则^%1/2%/ 3%? [R,L]
#要外部重定向/dir/foo.php?id=123到/ DIR / 123
?的RewriteCond%{THE_REQUEST} ^ GET S([^] +) PHP ID =([^&放大器; S] +) S [NC]
重写规则^%1 /%2? [R,L]
#在内部前进/ DIR /富/ 12 /dir/foo.php?id=12
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME -f .PHP
重写规则^(。+?)/([^ /] +)(/ [^ /] +)?/?$ $ 1.PHP?ID = $ 2 [L,QSA]
此外,article.php应检查 $ _ SERVER ['REQUEST_URI']
并执行重定向如果标题是不是在里面:
< PHP
$ ID = INTVAL($ _ GET ['身份证']);
$标题= titleById($ ID);
$ parsedurl =爆炸(/,$网址);
如果($ parsedurl [3]!= $标题){
标题(位置:http://www.example.com/article/$id/$title,真实,301);
出口();
}
I have used my .htaccess file to add www.
to index url , remove .php
and remove ?id=
from URLs.
This is original url:
www.site.com/article.php?id=12&title=title-text
Url with .htaccess code
www.site.com/article/12
This code have removed &title=title-text
from url.
How to remove &title=
without title-text
? Like this:
www.site.com/article/12/title-text
.htaccess file
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^ifeelvideos.com [NC]
RewriteRule ^(.*)$ http://www.ifeelvideos.com/$1 [L,R=301]
# To externally redirect /dir/foo.php?id=123 to /dir/foo
RewriteCond %{THE_REQUEST} ^GETs([^.]+).php?id=([^&s]+) [NC]
RewriteRule ^ %1/%2? [R,L]
# To internally forward /dir/foo/12 to /dir/foo.php?id=12
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/([^/]+)/?$ $1.php?id=$2 [L,QSA]
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^GETs([^.]+).phps [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*?)/?$ $1.php [L]
#Alternate default index pages
DirectoryIndex first.html index.htm index.html index.php
解决方案
I am assuming that article.php doesn't actually need the title to operate, only the id. You can only add the title to the url if the title exists in the url in the first place. You can leave out the second rule if title
is always in the url.
# To externally redirect /dir/foo.php?id=123&title=456 to /dir/123/456
RewriteCond %{THE_REQUEST} ^GETs([^.]+).php?id=([^&]+)&title=([^&s]+) [NC]
RewriteRule ^ %1/%2/%3? [R,L]
# To externally redirect /dir/foo.php?id=123 to /dir/123
RewriteCond %{THE_REQUEST} ^GETs([^.]+).php?id=([^&s]+)s [NC]
RewriteRule ^ %1/%2? [R,L]
# To internally forward /dir/foo/12 to /dir/foo.php?id=12
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/([^/]+)(/[^/]+)?/?$ $1.php?id=$2 [L,QSA]
Furthermore, article.php should check $_SERVER['REQUEST_URI']
and perform a redirect if the title is not in it:
<?php
$id = intval( $_GET['id'] );
$title = titleById( $id );
$parsedurl = explode( "/", $url );
if( $parsedurl[3] != $title ) {
header( "Location: http://www.example.com/article/$id/$title", true, 301 );
exit();
}