htaccess url重写,删除查询字符串和文件扩展名

时间:2011-03-19 07:57:03

标签: .htaccess url-rewriting

我当前的网址类似于:

http://something.somedomain.com/about_us/profile.php?tab1=about_us

更复杂的是: http://something.somedomain.com/exchange_hosting/feature/outlook_web_access.php?tab1=exchange_hosting&tab2=feature&tab3=outlook_web_access

我想让它们更短:

http://something.somedomain.com/about_us/profile http://something.somedomain.com/exchange_hosting/feature/outlook_web_access

我的.htaccess

#################################
# Directory Indexes             #
#################################
DirectoryIndex index.php

#########################################
# REWRITE RULES                         #
#########################################
RewriteEngine On
RewriteBase /

Options +FollowSymlinks
<IfModule mod_rewrite.c>

#not a file
RewriteCond %{REQUEST_FILENAME} !-f

#not a dir
RewriteCond %{REQUEST_FILENAME} !-d

#this dosen't work
#RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ /$1.php?tab1=$0&tab2=$1

</IfModule>

# END #

1 个答案:

答案 0 :(得分:1)

请尝试以下两种尺寸。对于更长的网址,你必须写更多这样的规则。

RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ $1/$2.php?tab1=$1&tab2=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ $1/$2/$3.php?tab1=$1&tab2=$2&tab3=$3 [L]