Htaccess文件和网址重写

时间:2012-04-23 22:28:14

标签: .htaccess url-rewriting

我有2个问题。

我目前正在使用wamp服务器来为我的网站服务。

主页是'localhost / prefix / index.php'

问题1:

一个。我想它,所以我的主页是:

'localhost/prefix/'

而不是

'localhost/prefix/index.php

湾我希望如此:

'localhost/prefix/admin/profile.php'

'localhost/prefix/admin/profile'

我该怎么做呢(我用google搜索,我对语法很困惑)?

问题2

如果我有像

这样的网址
'localhost/prefix/games?title=hi'

我怎么能这样做,所以url是这样的:

'localhost/prefix/games/hi'

提前致谢!! 我真的迷路了。

EDITED :: ///

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [R]             

到目前为止我有什么......它什么也没做......但是每个人都说它应该! (htaccess文件正在执行某些操作,因为如果我随机执行某些操作,则会引发错误)。

EDITED :: ///

这似乎从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

有什么想法吗?

EDITED :: ///

我已经怀疑上面的代码实际上是完美的,如果我指向的页面是在子文件夹中。所以例如..这将起作用:

localhost/prefix/admin/dashboard

但是这个(因为文件在根目录中,没有)

localhost/prefix/login.php

它将我重定向到

localhost/login

有什么想法吗?

EDIT :: ///

如果您在使用它时遇到问题。关闭浏览器并重新启动...我有缓存问题。

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

0 个答案:

没有答案