3

我的正则表达式尝试匹配所有结果并重定向到页面。我想将请求的地址发送到页面:

RewriteRule ^/[\w\W]*$ processor.php [R,NC,L]

例如,我的地址是:

www.mywebsite.com/mySecretCode123

我希望我的 php 文件能够读取它:

<?php echo $mySecretCode123; /* outputs 'mySecretCode123' */ ?>

我怎样才能做到这一点?

4

2 回答 2

3

.htaccees

# RewriteCond is condition - make rewrite only if file doesn't exists
# (.+) means "any character, one or more"
RewriteCond  %{REQUEST_FILENAME} !-f 
RewriteRule ^(.+)$ processor.php?mySecretCode=$1 

PHP

<?php echo $_GET['mySecretCode']; ?>
于 2012-08-31T13:33:49.047 回答
2

通过启用 mod_rewrite 和 .htaccess httpd.conf,然后将此代码放在您.htaccessDOCUMENT_ROOT目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request is not for a valid link
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ processor.php?$1=$1 [L,QSA]
于 2012-08-31T13:48:32.507 回答