2016-05-04 19 views
2

我正在開發一個PHP應用程序,其中我需要在獲取請求中使用正斜槓代替問號。像:如何使用正斜槓而不是問號發送請求?

www.example.com/article?aid=10 & aname = MY-文章

應改爲

www.example.com/article/10 /我-文章

以下是我的.htaccess:

Options +FollowSymlinks 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/$ http://example.com/$1 [R=301,L] 

# Redirect external .php requests to extensionless url 
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/ 
RewriteRule ^(.+)\.php$ http://example.com/$1 [R=301,L] 

# Resolve .php file for extensionless php urls 
RewriteRule ^([^/.]+)$ $1.php [L] 

RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^articles/(.*)$ articles?q=$1 [L,QSA,B] 

我已經嘗試了很多,但無法找到解決方案。這怎麼能做到?

回答

0

你可以做這樣的事情

RewriteRule ([^/\.]+)/([^/\.]+)/?$ page.php?level1=$1&level2=$2 [L] 

level然後描述完整的URL用符號在頁面假設稱爲分離/

然後page.php你可以這樣做:

$firstParameter = $_REQUEST["level1"]; 

在你的c萬一你可以這樣做:

RewriteRule article/([^/\.]+)/([^/\.]+)/?$ article?aid=$1&aname=$2 [L] 

那麼你的URL將被/article/foo/bar

注:

我通常使用RewriteBase /有基本的改寫與/, 這是把這樣:

Options +FollowSymLinks 
RewriteBase/

RewriteEngine On 
+0

我想轉換/ article?aid = foo&aname = bar到/ article/foo/bar –

+0

@VishalSuri - 你可以用這個做任何事情。你可以有你想要的水平。 Page.php只是您可以獲取信息的着陸頁的一個示例。如果你的文件被稱爲「文章」沒有問題,那麼「levels」的名稱可以按照你的意願調用它們,比如'aid','aname'。我已更新我的帖子 –

+1

Thanx很多。這工作正常。 –

0

您可以使用此規則重寫/條/富/酒吧/文章?援助= foo的& aname =酒吧 添加下列正確的波紋管RewriteEngine敘述上

RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^article/([^/]*)/([^/]+)/?$ /article?aid=$1&aname=$2 [L,QSA,B]