.htaccess rewriting url to page or directory

后端 未结 3 1864
悲&欢浪女
悲&欢浪女 2021-01-23 10:40

For my site I have a RewriteRule that points the URL http://www.mysite.com/work to a work.php file. I also have a directory called \"work\" that has files in it, like project1.p

3条回答
  •  囚心锁ツ
    2021-01-23 11:19

    Try this:

    RewriteEngin On
    RewriteBase /
    RewriteRule ^work$ /work.php [QSA,L]
    

    That will ensure that http://www.mysite.com/work (no trailing slash) will go to your work.php file.

    If you also want http://www.mysite.com/work/ (with trailing slash) to go work.php, add this line just above the last RewriteRule.

    RewriteRule ^work/$ /work [R=301,QSA,L]
    

    That will redirect it to the URL with no trailing slash thus, displaying the work.php file.

    UPDATE: Since you already have a RewriteBase directive, just put the RewriteRule line(s) right after your RewriteBase but before your RewriteRule as the rule you're using a catch-all and will match everything.

提交回复
热议问题