Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
Apache 在.htaccess中不工作的接线盒_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache 在.htaccess中不工作的接线盒

Apache 在.htaccess中不工作的接线盒,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我正在用PHP制作一个网站,我需要制作一个新闻页面。 我已经编写了news.php文件,它使用GET读取要显示的文章的特定标题。这意味着我最终会得到一个像 /community/news.php?title=post title 我更喜欢这样 /community/news/post title 所以我查了一下,发现我可以用.htaccess文件来做 现在,我的实际.htaccess文件看起来就像这样 ErrorDocument 404 /notfound.php <IfModule m

我正在用PHP制作一个网站,我需要制作一个新闻页面。 我已经编写了
news.php
文件,它使用
GET
读取要显示的文章的特定标题。这意味着我最终会得到一个像

/community/news.php?title=post title

我更喜欢这样

/community/news/post title

所以我查了一下,发现我可以用.htaccess文件来做

现在,我的实际.htaccess文件看起来就像这样

ErrorDocument 404 /notfound.php

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

# /community/news/post-title -> /community/news.php?title=post-title
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^community/news/([^/]*)$ /community/news.php?title=$1 [L]

</IfModule>
errordocument404/notfound.php
选项+FollowSymlinks
重新启动发动机
重写基/
#/community/news/post title->/community/news.php?title=post title
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^community/news/([^/]*)$/community/news.php?title=$1[L]
转到
/community/news/post title
的结果是404错误


非常感谢您的帮助。

如果您在本地环境中工作,并且您的url与“RewriteBase/”中的“website”类似


如果您在本地环境中工作,并且您的url类似于,那么您应该在“RewriteBase/”中有“website”


因此,假设您的url是example.com-(QSA标志将查询字符串附加到url)


因此,假设您的url是example.com-(QSA标志将查询字符串附加到url)


非常感谢你的帮助

原来是相对路径的问题。 它与:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

# /community/news/post-title -> /community/news.php?title=post-title
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/community/news/([^/]*)$ community/news.php?title=$1 [L]

</IfModule>

选项+FollowSymlinks
重新启动发动机
重写基/
#/community/news/post title->/community/news.php?title=post title
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^/community/news/([^/]*)$community/news.php?title=$1[L]

(区别在于最后一行的“/”)

非常感谢您的帮助

原来是相对路径的问题。 它与:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

# /community/news/post-title -> /community/news.php?title=post-title
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/community/news/([^/]*)$ community/news.php?title=$1 [L]

</IfModule>

选项+FollowSymlinks
重新启动发动机
重写基/
#/community/news/post title->/community/news.php?title=post title
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^/community/news/([^/]*)$community/news.php?title=$1[L]
(差异在最后一行的“/”中)

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

# /community/news/post-title -> /community/news.php?title=post-title
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/community/news/([^/]*)$ community/news.php?title=$1 [L]

</IfModule>