duankong8998 2014-05-18 12:44
浏览 15
已采纳

.htaccess rewriteRule with pageparameters [duplicate]

This question already has an answer here:

I'm finally asking my first question on Stackoverflow:

I'm creating a website which has the base template (header, menu, footer) as the index.php and all the content links will call the index.php with a parameter called '?page=asdf'. (I hope it's a reasonable strucutre for a business site.)

<div class="page_wrapper">
    <?php 
        if (isset($_GET['page'])){
                include 'tpl/'.$_GET['page'].'.php';    
        }
        else{
            include 'tpl/start.php';
        }
    ?>
</div>

Now i want to rewrite the urls without the .php at the end like page.com/index.php?get=products should be page.com/products. The same for 'about', 'contact' and so on. And the startpage should always be like page.com/

One of the important points is that it should be multilingual in English & German and I really don't know how to it. Do I have to make each Filename in German and English ?

I did it 2 years ago only with one language but I can't remind how I did it and lost the source code.

<=============================>

GOT IT:

I used RewriteRule ^([^/]+)/?$ index.php?page=$1 [L]

Thanks @Jon Lin for the help, you brought me to this idea.

</div>
  • 写回答

1条回答 默认 最新

  • dongpeixiong5943 2014-05-18 13:49
    关注

    Try:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)$ /index.php?page=$1 [L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图