dongxieting9623 2013-07-29 17:00
浏览 146
已采纳

.htaccess多个url重写

i have a project done ready..Now the client want to rewrite the entire url...ie(www.mydomain/page.php) to www.mydomain/page ect...

There are multiple pages.say about 10-15 in the folder..is there any possibility that we can rewrite the entire url of these pages at a given shot using .htaccess?

Also the links to these pages carry ".php" and ".html" extensions in order to navigate to another pages.. Now should I erase all these extensions manually or can i change it through other means(eg;.htaccess) Thanks

  • 写回答

3条回答 默认 最新

  • duanpen9294 2013-07-29 17:50
    关注

    you would need to add something to know if it's PHP or HTML, like

    all .php files becomes www.mydomain.com/p/page
    and .html files become www.mydomain.com/h/page
    

    (this would need another set of htaccess rules than the one below)

    or you can change all .html files to .php so it would be easier..
    you can now have all files hide their .php extension like

    www.mydomain.com/page.php becomes www.mydomain.com/page
    

    to do this, on your .htaccess put:

    RewriteEngine On
    
    # browser requests PHP
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
    RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
    
    # check to see if the request is for a PHP file:
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^/?(.*)$ /$1.php [L]
    

    I've edited my answer after some researching because you needed to add 301 redirects from the old links back to the new ones so the code above should work now. credits to the answer here: Redirect .php urls to urls without extension

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 三菱FX系列PLC串口指令
  • ¥15 cocos的js代码调用wx.createUseInfoButton问题!
  • ¥15 关于自相关函数法和周期图法实现对随机信号的功率谱估计的matlab程序运行的问题,请各位专家解答!
  • ¥15 Python程序,深度学习,有偿私
  • ¥15 扫描枪扫条形码出现问题
  • ¥35 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3