rev*_*ive 1 .htaccess mod-rewrite url-rewriting
这是针对基本的HTML/PHP页面,没有查询字符串等.我搜索了高低,找到了从URI中删除'index.php'的资源,或删除'.php'和其他文件扩展名.甚至添加一个尾部斜杠.但是,每次我尝试使用它们,或者使用我找到的示例时,我都会收到500服务器错误.
我可以在一个页面上传递查询字符串,但实际上我只想从索引页面中删除"index.php"并使所有子页面都没有文件扩展名.所以,像这样:
domain.com/index.php到domain.com/ domain.com/page1.php到domain.com/page1/ domain.com/page2.php到domain.com/page2/ domain.com/page3.php到域. COM /第3页/
我可以找到的所有示例都集中在CMS等等.查询字符串等等.没有什么只关注基本URI,我认为可能是导致我得到的错误的原因.
任何帮助表示赞赏!! 谢谢
我从一个论坛上的一个相当有帮助的小伙伴那里得到了这个 - 从来没有完全理解它,并且有一个警告; 除非请求是目录,否则它不表示没有尾部斜杠.
但是,我认为值得张贴 - 那里的古茹可能很容易发现修复!?
# remove .php; use THE_REQUEST to prevent infinite loops
RewriteCond %{HTTP_HOST} ^www\.domain\.com
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# remove index
RewriteRule (.*)index$ $1 [R=301]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6457 次 |
| 最近记录: |