我发誓我无法得到这个,我读了10个教程但无法使它工作......我想要漂亮的网址,所以我的目录结构就像这样
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.
答案 0 :(得分: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
是变量(可以是任何东西)。
答案 1 :(得分:1)
这就是你需要的:
RewriteEngine On
RewriteRule ^my_website\/home\/([a-z0-9_-]+)?$ my_website/home.php?page=$1 [L]