0

我发誓无法得到这个,我阅读了 10 个教程但无法使其工作......我想要漂亮的 url,所以我的目录结构是这样的

localhost/my_website/home.php?page=dashboard

我在具有这些规则的.htaccess文件夹中有一个文件my_website

#Redirect To Default Login Page
DirectoryIndex login.php

#Block Directory Listing
IndexIgnore * 

# Turn on URL rewriting
RewriteEngine On

RewriteRule ^page/([^/\.]+)/?$ home.php?page=$1 [L]

但是当我输入这个时,http://localhost/my_website/home/dashboard我实际上什么也没得到

我得到的是

The requested URL /my_website/home/dashboard was not found on this server.
4

2 回答 2

1

你可以试试这个:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /([^/]+)/([^/]+)$ [NC]
RewriteRule .*  my_website/%1.php?page=%2 [L,QSA]

它将静默映射:

http://localhost/my_website/anything1/anything2

到:

http://localhost/my_website/anything1.php?page=anything2

我假设home并且dashboard在问题中是变量(可以是任何东西)。

于 2013-01-06T11:48:24.237 回答
1

这就是您需要的:

 RewriteEngine On
 RewriteRule ^my_website\/home\/([a-z0-9_-]+)?$ my_website/home.php?page=$1 [L]
于 2013-01-06T11:54:25.120 回答