如何使用htaccess的缩短网址如何使用、网址、htaccess

2023-09-02 09:42:48 作者:历日旷久

您好球员,我需要使用htaccess的,以缩短我的网址 像

Hello guys i need to shorten my url using htaccess like

在的

www.mysite.com/obj/task/profile/id/1568/username

www.mysite.com/obj/task/profile/id/1568/username

在的

www.mysite.com/1568/username

www.mysite.com/1568/username

在的

www.mysite.com/obj/task/page/city/41280/pageId/22/clubs//Test%20town

怎么缩短网址

www.mysite.com/obj/task/page/city/41280/pageId/22/clubs//Test%20town

在的

www.mysite.com/41280/22/clubs//Test%20town

www.mysite.com/41280/22/clubs//Test%20town

我怎样才能实现这一点使用htaccess的

how can i achieved this using htaccess

我的htaccess的文件有这个

my htaccess file has this

RewriteEngine on
Options +FollowSymlinks
Options -Indexes

RewriteCond %{REQUEST_URI} (.+)$  [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
AddDefaultCharset utf-8
RewriteRule (.*) index.php 

RewriteEngine on
RewriteCond %{HTTP_HOST} ^test.com [NC]
RewriteRule ^(.*)$ http://www.test.com/$1 [L,R=301]  

建议更改的

Suggested Changed

<files .htaccess>
    order allow,deny
    deny from all
</files>
php_value memory_limit 170M

RewriteEngine on
Options +FollowSymlinks
Options -Indexes

RewriteCond %{REQUEST_URI} (.+)$  [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
AddDefaultCharset utf-8
RewriteRule (.*) index.php


#RewriteCond %{HTTPS} !=on
#RewriteCond %{HTTP_HOST} !^$ [NC] 
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

# THIS  RULE FOR FOR INACTIVE HTTPS
#RewriteCond %{HTTP_HOST} !^www.*$ [NC]
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 


RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]  

Options +FollowSymLinks -MultiViews

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]

我曾参观过的 www.mysite.com/obj/task/profile/id/1568/username 的 该链接仍然没有缩短。

I have visited www.mysite.com/obj/task/profile/id/1568/username The links is still not shorten.

推荐答案

的httpd.conf 启用了mod_rewrite和.htaccess,然后把这个code在< $ C C>的.htaccess $ DOCUMENT_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]