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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化