Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过.htaccess更改URL结构_Php_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php 通过.htaccess更改URL结构

Php 通过.htaccess更改URL结构,php,regex,apache,.htaccess,mod-rewrite,Php,Regex,Apache,.htaccess,Mod Rewrite,我知道apache.htaccess文件能够重写URL,使它们更可读、更高效,但我不知道如何实现这一点 假设我有以下几种URL: http://mywebsite.com/index.php?mode=home http://mywebsite.com/index.php?mode=articles http://mywebsite.com/index.php?mode=about 但我想让这些看起来更漂亮,更可读。大概是这样的: http://mywebsite.com/home http:

我知道apache.htaccess文件能够重写URL,使它们更可读、更高效,但我不知道如何实现这一点

假设我有以下几种URL:

http://mywebsite.com/index.php?mode=home
http://mywebsite.com/index.php?mode=articles
http://mywebsite.com/index.php?mode=about
但我想让这些看起来更漂亮,更可读。大概是这样的:

http://mywebsite.com/home
http://mywebsite.com/articles
http://mywebsite.com/about
对于像我这样的apache新手来说,这似乎是一项复杂的任务


非常感谢您的帮助。

将此代码放入您的
文档\u ROOT/.htaccess
文件:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^/]+)/?$ index.php?mode=$1 [QSA,L]

参考:重复了这么多其他问题,检查起来很痛苦