带有htaccess重定向的php页面不工作
我试图在我的php站点上将非www重定向到www,并保持URL干净,而不必链接到.php页面带有htaccess重定向的php页面不工作,php,.htaccess,mod-rewrite,redirect,url-rewriting,Php,.htaccess,Mod Rewrite,Redirect,Url Rewriting,我试图在我的php站点上将非www重定向到www,并保持URL干净,而不必链接到.php页面 #This bit rewrites your host name to include www RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC,L] #This bit does the codeigniter magic RewriteC
#This bit rewrites your host name to include www
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC,L]
#This bit does the codeigniter magic
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
当我为下面的非www到www使用建议重定向时,页面链接不再指向正确的页面。例如:我有一个page1.php,当我链接到domain.com/page1(不带.php)时,该页面将不再加载。我怎样才能解决这个问题?我是否必须修改所有链接并添加页面扩展(.php)才能使链接正常工作
#This bit rewrites your host name to include www
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC,L]
#This bit does the codeigniter magic
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
我正在使用的htaccess:
#This bit rewrites your host name to include www
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC,L]
#This bit does the codeigniter magic
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
重新启动发动机
#This bit rewrites your host name to include www
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC,L]
#This bit does the codeigniter magic
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
我找到了答案
#This bit rewrites your host name to include www
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC,L]
#This bit does the codeigniter magic
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteEngine On
RewriteBase /
#Rewrite bare to www
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
您是否为
/page1
设置了路由,或者page1.php
文件实际上不存在?我的所有页面都是page.php格式。但是链接是/page/page1/page2等等……那么您是否使用CodeIgniter?一般来说,这并不是你在一个网站上施展的魔法,它能让URL像你想的那样工作。您需要将这些页面转换为控制器和视图,然后适当地设置路由。如果您已经这样做了,那么请给我们一些关于您的路由的详细信息,以便我们能够帮助您解决.htaccess
指令不足以继续的问题。不,这是一个带有.php页面的普通网站,您需要删除最后3条指令。但是,您必须使用page.php
访问页面,这意味着更改所有链接。我很好奇你以前是怎么做到的。。。