且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用htaccess缩短网址

更新时间:2023-11-27 19:54:16

通过 httpd.conf 启用 mod_rewrite 和 .htaccess 然后把这段代码放到你的 .htaccessDOCUMENT_ROOT 目录:

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# from /obj/task/profile/id/1568/username
# to /1568/username
RewriteRule ^obj/task/profile/id(/.+)$ /$1 [R=302,L,NC]

# from obj/task/page/city/41280/pageId/22/clubs//Test%20town
# to 41280/22/clubs//Test%20town
RewriteRule ^obj/task/page/city/([^/]+)/pageId(/.+?)/?$ /$1/$2 [R=302,L,NC,NE]