【发布时间】:2013-04-16 21:47:54
【问题描述】:
我知道有很多话题。我尝试了很多次,但它不起作用。
我想要什么?
用户只能看到example.com/en/file,而不是example.com/en/file.php。
我的.htaccess file:
DirectoryIndex index.php index.html
RewriteEngine on
*RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ /$1.php*
ErrorDocument 404 /index.php
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^ru\/index\.php$ "http\:\/\/example\.com\/ru\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^en\/index\.php$ "http\:\/\/example\.com\/en\/" [R=301,L]
等等。每种语言
-
我必须添加什么来隐藏扩展?
-
它工作后,我应该使用页面之间的链接作为“file.php”还是只使用“file”?
【问题讨论】:
-
检查
RewriteRule语法 - 正好相反。第一个是“改写什么”,第二个是“改写的结果” -
这一定是我在 SO 上看到的被问得最多的问题,在发布之前执行搜索并没有什么坏处
-
这就像黑客,你总是最好使用一个简单的 PHP 框架。如果您想试一试,请尝试 CodeIgniter 或 CakePHP :)
标签: php