.htaccess rewriting url to page or directory

后端 未结 3 1861
悲&欢浪女
悲&欢浪女 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:16

    Try this rule:

    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule .* $0.php [L]
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-23 11:20

    This is the answer to your question. It works for me.

    RewriteEngine On
    RewriteBase /
    RewriteRule ^([a-z]+)$ $1.php [L]
    

    Simply remove beta/

    0 讨论(0)
提交回复
热议问题