Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 使用htaccess更改URL_.htaccess - Fatal编程技术网

.htaccess 使用htaccess更改URL

.htaccess 使用htaccess更改URL,.htaccess,.htaccess,我在文件夹public(root/public)中有一个.htaccess文件 我希望实现以下转变: /index.php->/ index.php?site=siteName->/siteName/ /siteName/或/siteName->用作?site=siteName 这是我目前为止完整的.htaccess文件(已解决案例3): 您可以使用其他规则将旧URL重定向到pretty URL和index.php删除: RewriteEngine On # external redirect

我在文件夹
public
(root/public)中有一个.htaccess文件

我希望实现以下转变:

  • /index.php
    ->
    /
  • index.php?site=siteName
    ->
    /siteName/
  • /siteName/
    /siteName
    ->
    用作?site=siteName
  • 这是我目前为止完整的.htaccess文件(已解决案例3):


    您可以使用其他规则将旧URL重定向到pretty URL和
    index.php
    删除:

    RewriteEngine On
    
    # external redirect from actual URL to pretty one
    RewriteCond %{THE_REQUEST} /index\.php\?current=([^\s&]+) [NC]
    RewriteRule ^ /%1? [R=302,L,NE]
    
    # remove index.php
    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*)index\.php$ /$1 [L,R=302,NC,NE]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?current=$1 [L,QSA]
    

    是的,一个是示例,另一个是在我的演示项目中使用的实际代码。
    RewriteEngine On
    
    # external redirect from actual URL to pretty one
    RewriteCond %{THE_REQUEST} /index\.php\?current=([^\s&]+) [NC]
    RewriteRule ^ /%1? [R=302,L,NE]
    
    # remove index.php
    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*)index\.php$ /$1 [L,R=302,NC,NE]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?current=$1 [L,QSA]