我有我用php編寫的網站。Htaccess重定向問題
的地址如下:
http://www.site.com/page.php
我想任何請求:
www.site.com/page.php
或
www.site.com/page
要前往:
w ww.site.com/page/
(並強制WWW)
誰能幫助我?
我有我用php編寫的網站。Htaccess重定向問題
的地址如下:
http://www.site.com/page.php
我想任何請求:
www.site.com/page.php
或
www.site.com/page
要前往:
w ww.site.com/page/
(並強制WWW)
誰能幫助我?
RewriteRule ^page.php$ http://www.site.com/page/ [QSA,L]
RewriteRule ^page$ http://www.site.com/page/ [QSA,L]
也許這會奏效。
對於域:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
對於你的第一個目錄:
RewriteRule ^/([^/]*)(\.php)? /$1/
這應該做你想要的東西:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/([^\s]*?)\.php [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/([^\s]*?[^/\s])\s [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST}/%1 ^(www\.)?(.*?)/?$
RewriteRule^http://www.%2/ [R=301,L]
# Assuming you want to write the request back to page.php too...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/$ $1.php
蒂姆的答案是最接近的,但它也確實將斜線添加到圖像和css ...
因此,採取添的回答,並稍微修改它給了我們:
RewriteEngine on
RewriteRule \.(css|jpe?g|gif|png)$ - [L]
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/([^\s]*?)\.php [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]+\s/([^\s]*?[^/\s])\s [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST}/%1 ^(www\.)?(.*?)/?$
RewriteRule^http://www.%2/ [R=301,L]
# Assuming you want to write the request back to page.php too...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/$ $1.php
這應該工作!
這似乎是從'http:// domain.com/page'重定向到'http:// www.domain.com',而不是保留頁面。 – Robert 2010-08-19 20:11:05