htaccess url rewrite,remove querystring and file extension

早过忘川 提交于 2019-12-25 14:07:57

问题


my current url is something like:

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

a more complicated on is: http://something.somedomain.com/exchange_hosting/feature/outlook_web_access.php?tab1=exchange_hosting&tab2=feature&tab3=outlook_web_access

i want to make them shorter:

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

my .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:


Try following for two sizes. For more lengthier url you have to write more such rules.

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]


来源:https://stackoverflow.com/questions/5360885/htaccess-url-rewrite-remove-querystring-and-file-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!