我的正则表达式尝试匹配所有结果并重定向到页面。我想将请求的地址发送到页面:
RewriteRule ^/[\w\W]*$ processor.php [R,NC,L]
例如,我的地址是:
www.mywebsite.com/mySecretCode123
我希望我的php文件能够读取它:
<?php echo $mySecretCode123; /* outputs 'mySecretCode123' */ ?>
我该怎么做?
答案 0 :(得分: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']; ?>
答案 1 :(得分:2)
通过httpd.conf
启用mod_rewrite和.htaccess,然后将此代码放在.htaccess
目录下的DOCUMENT_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]