2011-01-28 155 views
0

重寫,我發現關於URL重寫一些問題: .htaccess: Problem with URL rewriting.htaccess question - URL-rewriting網址的.htaccess

我想他們的方法,但不工作在我的情況? 礦看起來很簡單:

http://example.org.uk/member/home.php?profile --> http://example.org.uk/member/home/profile/ 
http://example.org.uk/member/home.php?history --> http://example.org.uk/member/home/history/ 

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
#RewriteRule ^home/([0-9][0-9])/$ /home.php?$1 
RewriteRule ^/([^/]+).php$ /home.php?$1 [L] 

任何thougt是appricated?謝謝

+0

您的規則和示例相互矛盾。你想把`home.php?profile`映射到`home/profile`(例子)還是`home/profile`被重寫爲`home.php?profile`(重寫代碼)? – 2011-01-28 17:53:26

+0

@Linus:我想映射到家庭/配置文件,並刪除PHP前。 – tonoslfx 2011-01-28 17:54:45

回答

4

你使它有點複雜,下面應該工作

http://example.org.uk/member/home.php?profile --> http://example.org.uk/member/home/profile/ 
http://example.org.uk/member/home.php?history --> http://example.org.uk/member/home/history/ 



RewriteRule ^/member/home/(.*)/ /home.php?$1 [L] 

或者更一般

RewriteRule ^/(.*)/(.*)/(.*)/ /home.php?$3 [L] 
0

在RewriteRule中,你有「^ /([^ /] +).php $」,但是你不想在URL中使用.php擴展名。從重寫規則中刪除.php。 像這樣的東西應該工作:

RewriteRule ^/member/home/.*$ /member/home.php?$1 [L] 
-1

它仍然會尋找」。 php「,因此你可以使用

RewriteRule ^/([^/]*)/$ home.php?$1 
0
Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^/member/home/([a-zA-z0-9]+)/$ /member/home.php?$1 [L]