如何在htaccess中设置重写

时间:2019-01-25 18:30:32

标签: php .htaccess

我有这个htaccess:

Options +FollowSymLinks
RewriteEngine on
RewriteRule cache/ - [F]
Options -Indexes

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-zA-Z0-9\-\_\/]*)$ index.php?p=$1


# Blokada hotlinking czyli kradzieży obrazków
RewriteCond %{HTTP_REFERER} !^https://(.+\.)?nazwadomeny.pl/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !yahoo\. [NC]




# Prevent viewing of htaccess file.
<Files .htaccess>
    order allow,deny
    deny from all
</Files>
RedirectMatch 403 ^.*/apps/(.*).php(.*)$

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl|map)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

在php中我有这个(我的路由器):

$explodeUrl = explode('/', $url);
$request->controller = ucfirst($explodeUrl[0]);
$request->action = $explodeUrl[1] ?? 'index';
$request->params = $explodeUrl[2] ?? [];

当我有此网址时,一切正常:

- www.domain.com\sample
- www.domain.com\contact
- www.domain.com\option\value
- www.domain.com\url\id
- www.domain.com\product\name\id

问题出在我有这个网址:

- www.domain.com\product?id=1
- www.domain.com\viewCity?build=123

然后我得到结果:viewCity?build=123product?id=1

问题在于,此行位于:RewriteRule ^([a-zA-Z0-9\-\_\/]*)$ index.php?p=$1

结果,我只需要:viewCity或产品-没有?....

如何维修?

0 个答案:

没有答案