2015-05-11 42 views
2

我想製作example.org/fish並獲取標籤,但是,我的腳本將標籤弄錯了。這是我的htacess;簡單的htaccess技巧

DirectoryIndex index.php 

Options +FollowSymLinks 
RewriteEngine On 

RewriteRule ^(.*)$ index.php?tag=$1 

的index.php

echo $_REQUEST[tag] 

輸出

index.php 

什麼是讓標籤名稱的正確方法是什麼?

回答

4

您需要禁止規則中的現有文件和目錄,否則您的規則第二次運行index.php作爲URI,並使tag參數爲index.php

DirectoryIndex index.php 
Options +FollowSymLinks 
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ index.php?tag=$1 [L,QSA] 
+1

就像一個魅力。非常感謝! – user198989

+0

不客氣,很高興它的工作。 – anubhava

+1

當然,我只是在等待10分鐘的接受區塊結束;) – user198989

2
Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ index.php?tag=$1 [L,QSA] 

然後調用標籤中的index.php作爲,

echo $_GET['tag'];