2013-03-25 52 views
0

我有URL,將是這樣的:如何更改URL使用.htaccess中的重寫文件?

http://example.com/directory/index.php?q=anything 

使得PHP將加載使用$ _GET [ 'Q']測試變量。

我希望在我的.htaccess簡化這:

http://example.com/directory/anything.html 

我怎麼會去這樣做?

+0

有一個類似的問題,可能是一些對你有價值。 [htaccess重寫查詢字符串](http://stackoverflow.com/questions/1231067/htaccess-rewrite-for-query-string) – Ohgodwhy 2013-03-25 06:05:25

+0

http://stackoverflow.com/questions/15512690/redirect-dynamic-urls-including -querystring-with-htaccess – 2013-03-25 06:05:54

+0

你使用什麼框架? – 2013-03-25 06:13:40

回答

1

可能是你可以在.htaccess

RewriteEngine on 

RewriteRule ([0-9A-Za-z-\+._]+)\.html$ ./index.php?q=$1 
0

添加這樣的事我自己解決這個問題:: 這裏的的.htaccess代碼

RewriteEngine On 
RewriteRule ^directory/([^/]*)\.html$ /directory/index.php?q=$1 [L]