2011-10-22 50 views
3

我一直沒有任何結果搜索諸如3或4小時(搜索我之前打了規則了一個小時,但不能這樣做)從URL中移除的symfony www和index.php文件

我不'不知道你是否注意到或沒有,但谷歌使用這樣的www

當它沒有子域時,它將是www.google.com/blabla和 當有子域它會earth.google.com/blabla

這是第一部分

第二部分,正如你在symfony網站上所知道的,就像domain.com/index.php/test一樣,感謝symfony .htaccess文件,你可以通過domain.com/test來訪問它 所以這裏是我努力嘗試的實現

domain.com/test重定向到www.domain.com/test

www.sub.domain.com/blabla重定向到sub.domain.com/blabla

www.sub.domain .com /重定向到sub.domain.com(沒有任何index.php XD)

其中一個令人討厭的問題是從domain.com/重定向到www.domain.com是t重新定向後它是像www.domain.com/index.php(我討厭index.php:P)

那麼有一種方式,一個重定向解決這個問題? 我敢肯定,我不是誰需要這樣的事情,可能是其他人的想法誰是要擁有自己的網站用symfony或其他框架 感謝

這裏是我的完整htaccess文件

只有一個
Options +FollowSymLinks +ExecCGI 

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    # The admin subdomain returns to the backend 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{HTTP_HOST} ^admin\.mydomain\..* 
    RewriteRule ^(.*)$ backend.php [QSA,L] 

    # uncomment the following line, if you are having trouble 
    # getting no_script_name to work 
    #RewriteBase/

    RewriteCond %{HTTP_HOST} !^www.mydomain.com$ 
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301] 

    # we skip all files with .something 
    RewriteCond %{REQUEST_URI} \..+$ 
    RewriteCond %{REQUEST_URI} !\.html$ 
    RewriteRule .* - [L] 

    # we check if the .html version is here (caching) 
    RewriteRule ^$ index.html [QSA] 
    RewriteRule ^([^.]+)$ $1.html [QSA] 
    RewriteCond %{REQUEST_FILENAME} !-f 

    # no, so we redirect to our front web controller 
    RewriteRule ^(.*)$ index.php [QSA,L] 
</IfModule> 
+0

你有 no_script_name:在你的settings.yml中的督促下,部分真實 和: 重寫規則^ $的index.php [QSA,L] htaccess的(*)? – Jestep

回答

1

在你VHOST配置:

RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC] 
RewriteRule ^/(.*) http://domain.com/$1 [R=301,L] 

還要注意的是從一個審美角度,你可能更願意去除WWW,從技術的角度看(DNS,餅乾,...) ,pref總是更好ix與www,並以相反的方式重定向。

+0

感謝您的回答,但它不符合我所要求的 我將按照您的說法執行操作(包括所有域的www,但從domain.com重定向到www.domain.com的問題依然存在因爲它重定向到www.domain.com/index.php – Moein

+0

它只會重定向到/index.php,如果原始請求包含/index.php。我認爲你錯過了別的。 – Gerry

+0

不,它不需要有index.php 自從您輸入domain.com以來,由於默認頁面是index.php,並且由於您在www.domain.com末尾有$ 1,它將變爲www.domain.com/index.php – Moein