.htaccess Htaccess文件和url重写

.htaccess Htaccess文件和url重写,.htaccess,url-rewriting,.htaccess,Url Rewriting,我有两个问题 我目前正在使用wamp服务器为我的网站提供服务 主页是“localhost/prefix/index.php” 问题1: a。我希望我的主页是: 'localhost/prefix/' 而不是 'localhost/prefix/index.php b。我希望如此: 'localhost/prefix/admin/profile.php' 是 我怎么做呢?我在谷歌上搜索过,我对语法感到非常困惑 问题2 如果我有一个像 'localhost/prefix/games?title

我有两个问题

我目前正在使用wamp服务器为我的网站提供服务

主页是“localhost/prefix/index.php”

问题1:

a。我希望我的主页是:

'localhost/prefix/'
而不是

'localhost/prefix/index.php
b。我希望如此:

'localhost/prefix/admin/profile.php'

我怎么做呢?我在谷歌上搜索过,我对语法感到非常困惑

问题2

如果我有一个像

'localhost/prefix/games?title=hi'
我如何使其url如下所示:

'localhost/prefix/games/hi'
提前谢谢!! 我真的迷路了

编辑::///

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [R]             
这就是我目前所拥有的。。它什么都不做。。。但是每个人都说应该!htaccess文件正在做一些事情,因为如果我做一些随机的事情,它会抛出错误

编辑::///

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [R]             
这似乎从url中删除了.php和index.php:

RewriteEngine On
RewriteBase /prefix/

# remove .php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]


# remove index
RewriteRule (.*)/index$ $1/ [R=301]

# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]

# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]          
现在的问题是,我的前缀库不起作用,所以它最终会

localhost/something/something
而不是

localhost/prefix/something/something
有什么想法吗

编辑::///

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [R]             
我发现,如果我指向的页面位于子文件夹中,那么上面的代码实际上可以完美地工作。比如说。。这将有助于:

localhost/prefix/admin/dashboard
但这是因为文件位于根目录中,所以

localhost/prefix/login.php
它使我转向

localhost/login
有什么想法吗

编辑::///

如果你在工作中遇到问题。关闭浏览器并重新启动。。。我有缓存问题


上面的代码将删除.php,也将删除index.php。

?在根文件夹中是否有其他索引.*、默认.*或主.*文件?正确。localhost/prefix正确指向index.php。。问题是,我不得不更改的链接是指向localhost/prefix/index.php的,所以问题1A和b在这方面非常相似,所以我只想把.php去掉。但是,我还想知道如果index.php是localhost/prefix,如何将其从末尾删除。有道理?。。。。。。。。。我在根目录中还有许多.php文件。像login.php之类的目录。它需要是localhost/prefix/login如果localhost/prefix/index.php存在,我真的不认为有链接到它的HREF有什么问题…我喜欢wordpress如何显示其url,并希望复制它。但是,您的HREF已经链接到index.php-URL重写仅适用于重写您链接到的URL;例如,如果您想将index.php重命名为另一个-file.php,您可以使用mod_rewrite来防止更改所有链接,但index.php仍将显示在地址栏中,因为href就是这么说的!我不是一个完全的专家,如果其他人知道怎么做,我会很高兴被证明是错的