.htaccess change a path to a query strings

前端 未结 1 1380
别跟我提以往
别跟我提以往 2021-01-21 11:15

I have files in example.com/

contact.php
recent.php
videos.php
watch.php

example.com/page/ > /page/ is not a folder.

相关标签:
1条回答
  • 2021-01-21 11:23

    You can combine regex and shorten your rules in your .htaccess with QSA flag:

    RewriteEngine on
    RewriteBase /
    
    # add www in host name
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*?)/?$ http://www.%{HTTP_HOST}/$1 [R=301,NE,L]
    
    # Unless directory, remove trailing slash
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ /$1 [NE,R=301,L]
    
    RewriteRule ^page/(submit|contact|search|recent|playlist)/?$ $1.php [L,NC]
    
    RewriteRule ^page/(videos|watch)/([^/]+)/?$ $1.php?title=$2 [L,QSA,NC]
    
    0 讨论(0)
提交回复
热议问题