我使用下面的URL在.htaccess重写。
I am using the following URL rewriting in .htaccess.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]+)/([a-zA-Z0-9&_,-]+)$ business/business_home.php?business_id=$1 [L,QSA]
RewriteRule ^([0-9]+)/([a-zA-Z0-9&_,-]+)/(about)$ business/business_about.php?business_id=$1 [L,QSA]
RewriteRule ^([0-9]+)/([a-zA-Z0-9&_,-]+)/(products)$ business/business_products.php?business_id=$1 [L,QSA]
RewriteRule ^([0-9]+)/([a-zA-Z0-9&_,-]+)/(enquiry)$ business/business_enquiry.php?business_id=$1 [L,QSA]
RewriteRule ^([0-9]+)/([a-zA-Z0-9&_,-]+)/(contact)$ business/business_contact.php?business_id=$1 [L,QSA]
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s([^.]+).php[s?] [NC]
RewriteRule ^ - [R=404,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]
那么如何获取当前rewrited网址不包括查询字符串?
对于如:从具有URL页面: / 22 / somestring /查询值= 5和第= 9和;项目=咖啡
我预计: / 22 / somestring /查询
Then How to get current rewrited URL excluding querystring?
For eg: From the page having URL: /22/somestring/enquiry?value=5&page=9&item=coffee
I expect: /22/somestring/enquiry
我试着用 $ _ SERVER ['REQUEST_URI']
,但它返回 / 22 / somestring /查询值= 5和?页= 9和;项目=咖啡
并且还 $ _ SERVER ['REDIRECT_URL']
给我我所期待的,但它会生成一个注意:未定义指数:REDIRECT_URL
在一些网页。而且也它不能在某些服务器工作。
I tried with $_SERVER['REQUEST_URI']
but it return /22/somestring/enquiry?value=5&page=9&item=coffee
And also $_SERVER['REDIRECT_URL']
give me what I expected, but it generates an Notice: Undefined index: REDIRECT_URL
in some pages. And also it doesn't work in some servers.
在你PHP可以用code这样来获得当前URI的没有查询字符串
In you PHP you can use code like this to get current URI without query string:
$thisuri = preg_replace('/?.*$/', '', $_SERVER["REQUEST_URI"]);