.htaccess重写; 但需要变量

问题描述:

Hello Stackers,

I Currently have a Problem with my HTACCESS file. It needs to rewrite a Url, which it does, but I still need a Variable to pass through.

RewriteRule ^ref/(.*)$ /quickregister/start.php?ref=$1

The Link used is example.com/ref/value however, after the rewrite, no variables are recognizable, but I need the value of the REF variable.

Is there A way to do this? Also, I would preffer to still get if(isset($_GET['ref'])){ working.

Hello Stackers, strong> p>

我目前有 我的HTACCESS文件出现问题。 它需要重写一个Url,但它仍然需要一个变量来传递。 p>

  RewriteRule ^ ref /(.*)$/quickregister/start.php  ?ref = $ 1 
  code>  pre> 
 
 

使用的链接是 example.com/ref/value code>但是,在重写之后,没有可识别的变量, 但是我需要REF变量的值。 p>

有没有办法做到这一点? 此外,我还会得到 if(isset($ _ GET ['ref'])){ code> working。 p> div>

This is my standard .htaccess file which I use for all of my rewrite websites...

## No directory listings
IndexIgnore *

## Can be commented out if causes errors, see notes above.
Options +FollowSymlinks
Options -Indexes

## Mod_rewrite in use.

RewriteEngine On

# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects


RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

Using this file everything in the URL if it is not a valid directory or file is ignored and routed to index.php in the site root. I then access it as a single paramater using $_SERVER['REQUEST_URI'] which I can explode using explode("/", $_SERVER['REQUEST_URI']), this gives me an array starting at index 0 of each value. Using this script I am still able to access $_GET variables as long as at the end of the URI the convention ?var_name=value has been used.

This has been tested and works with Apache, PHP5 and works both debian based linux operating systems as well as Windows installs of Apache.