Php htaccess未重写我的GET请求的url

Php htaccess未重写我的GET请求的url,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我正在使用以下url导入我的所有页面模板: www.example.com/tournament/index.php?view=* 我想把这个改写成 www.example.com/tournament/* 所以 www.example.com/tournament/index.php?view=profile变为www.example.com/tournament/profile 及 www.example.com/tournament/index.php?view=profile&id=te

我正在使用以下url导入我的所有页面模板:

www.example.com/tournament/index.php?view=*

我想把这个改写成

www.example.com/tournament/*

所以

www.example.com/tournament/index.php?view=profile
变为
www.example.com/tournament/profile

www.example.com/tournament/index.php?view=profile&id=testUser
变成
www.example.com/tournament/profile/testUser

我目前已尝试:

RewriteRule ^tournament/([^/]*)/([^/]*)$ index.php?view=$1&id=$2
RewriteRule ^tournament/([^/]*)/([^/]*)$ index.php?view=$1&id=$2 [L]
RewriteRule ^tournament/([^/]*)/([^/]*)$ tournament/index.php?view=$1&id=$2
RewriteRule ^tournament/([^/]*)/([^/]*)$ tournament/index.php?view=$1&id=$2 [L]
RewriteRule ^tournament/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ index.php?view=$1&id=$2
RewriteRule ^tournament/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ tournament/index.php?view=$1&id=$2
但这是行不通的。我还打开了
重写引擎

以下文件结构是:

|public
|->tournament
    |->templates
        |-> profile.php
    |->index.php
    |->.htaccess (with rewriting in)
提前谢谢

编辑index.php


以下规则可以处理两个URL:

RewriteEngine on
RewriteCond %{THE_REQUEST} /tournament/index.php\?view=([^&]+)&id=([^&\s]+) [NC]
RewriteRule ^ /tournament/%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?:tournament/)?([^/]+)/?(.*)/?$ /tournament/index.php?view=$1&id=$2 [NC,L]

由于您的htaccess位于
锦标赛
文件夹中,因此您可以通过这种方式使用它

RewriteEngine On
RewriteBase /tournament/

# Redirect /tournament/index.php?view=XXX to /tournament/XXX
RewriteCond %{THE_REQUEST} \s/tournament/index\.php\?view=([^&\s]+)\s [NC]
RewriteRule ^ %1? [R=301,L]

# Redirect /tournament/index.php?view=XXX&id=YYY to /tournament/XXX/YYY
RewriteCond %{THE_REQUEST} \s/tournament/index\.php\?view=([^&\s]+)&id=([^&\s]+)\s [NC]
RewriteRule ^ %1/%2? [R=301,L]

# Skip if existing file/folder
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# Internally rewrite them back
RewriteRule ^([^/]+)$ index.php?view=$1 [L]
RewriteRule ^([^/]+)/([^/]+)$ index.php?view=$1&id=$2 [L]

“不改变”是什么意思?您在浏览器中键入了什么url?我希望这会变成
http://dev2.csgoberry.com/tournament/profile/matt500b/
但是什么也没发生重写成功了,但是现在我的页面根本无法加载;查看有关如何使用?view=*提取模板文件的问题的更新。如果此版本的htaccess存在与css和js相关的问题,则页面会出现
内部服务器错误
。Justin lurman的版本有一个css/js问题,我现在正试图解决这个问题。重写成功了,但是现在我的页面的css/js文件无法加载;查看我关于如何使用?view=*获取模板文件的问题的更新。对于所有资源(如js、css等),您需要使用绝对路径而不是相对路径。如果您需要帮助,请阅读我写的关于您的问题的回答:目前为止工作得很好再问一个问题。。通常我会做
你有两个解决方案。第一个(最懒惰的)是保留实际的html链接,并在需要时依靠htaccess将旧链接重定向到新链接。第二个(最干净的)是用(直接)相应的新链接替换所有旧的html链接。例如,您将使用
而不是
index.php?view=xxx&id=yyy&edit=true
版本
RewriteEngine On
RewriteBase /tournament/

# Redirect /tournament/index.php?view=XXX to /tournament/XXX
RewriteCond %{THE_REQUEST} \s/tournament/index\.php\?view=([^&\s]+)\s [NC]
RewriteRule ^ %1? [R=301,L]

# Redirect /tournament/index.php?view=XXX&id=YYY to /tournament/XXX/YYY
RewriteCond %{THE_REQUEST} \s/tournament/index\.php\?view=([^&\s]+)&id=([^&\s]+)\s [NC]
RewriteRule ^ %1/%2? [R=301,L]

# Skip if existing file/folder
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# Internally rewrite them back
RewriteRule ^([^/]+)$ index.php?view=$1 [L]
RewriteRule ^([^/]+)/([^/]+)$ index.php?view=$1&id=$2 [L]