2012-10-23 25 views
0

我的地方項目的根是本地主機/網站的.htaccess重寫類似文件夾的網址,以現有的HTML頁面

我創建了以下內容的文件本地主機/網站/的.htaccess:

RewriteEngine On 
RewriteRule ^content/(.*)$ content/$1.html [L] 

我真正想要實現的: localhost/website/main - >localhost/website/content/main.html 其中localhost/website/content/ma in.html實際上確實存在。

我嘗試了幾個規則,但沒有一個爲我工作。不知何故,我想我錯過了一些東西。

回答

1

如果您想將/main重定向到/content/main,您必須從第一個參數中省略content/

+0

嘗試過了,它給了我一個內部服務器錯誤。 apache log: 「由於可能的配置錯誤,請求超過了10個內部重定向的限制。使用'LimitInternalRecursion'在必要時增加限制,使用'LogLevel debug'獲得回溯。 我想這也與重寫條件:!。 的RewriteCond%{} THE_REQUEST ^內容/(.*)$ [NC] – mherwig

1

以下的伎倆

RewriteEngine On 

RewriteCond %{REQUEST_URI} !^.*content/[^/]*\.html$ 
RewriteRule ^(.*)$ content/$1\.html [L] 
+1

'RewriteEngine敘述在 的RewriteCond%{REQUEST_URI}^*含量/ [^ /] * \。html $ RewriteRule^/(。*)$ content/$ 1 \ .html [L]' – mherwig