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 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型