本文介绍了PHP如何获取当前rewrited网址不包括查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的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=coffeeI 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=coffeeAnd 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"]);

这篇关于PHP如何获取当前rewrited网址不包括查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 07:17