2016-02-10 02:04
采纳率: 0%
浏览 42

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

图片转代码服务由CSDN问答提供 功能建议

Hello Stackers,

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

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

使用的链接是 但是,在重写之后,没有可识别的变量, 但是我需要REF变量的值。

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

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • duanchi1230 2016-02-10 06:05

    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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题