Php Mod Rewrite for.htaccess
我的URL当前是这样的:Php Mod Rewrite for.htaccess,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我的URL当前是这样的:http://www.example.com/?content=contact.php 但我希望用户在URL字段中包含以下内容:http://www.example.com/contact.php 我已将此添加到.htaccess文件中: RewriteEngine On RewriteRule ^([^/]*)$ /?content=$1 [L] 但我现在得到了这个错误: 内部服务器错误 服务器遇到内部错误或配置错误,无法正常运行 无法完成您的请求 请联系服务器管理员
http://www.example.com/?content=contact.php
但我希望用户在URL字段中包含以下内容:http://www.example.com/contact.php
我已将此添加到.htaccess文件中:
RewriteEngine On
RewriteRule ^([^/]*)$ /?content=$1 [L]
但我现在得到了这个错误:
内部服务器错误
服务器遇到内部错误或配置错误,无法正常运行
无法完成您的请求
请联系服务器管理员,[未提供地址]并通知
告诉他们错误发生的时间,以及您可能做的任何事情
这可能是导致错误的原因
有关此错误的详细信息,请参阅服务器错误
日志
Apache/2.2.14(Ubuntu)服务器,位于www.example.com端口80
我做错了什么?像这样尝试我假设contact.php不是一个实际的文件
RewriteEngine on
RewriteRule ^(.*)$ ?content=$1 [QSA,L]
这应该行得通
RewriteRule ^(.*)$ index.php?content=$1
此规则将所有请求重定向到index.php,并作为GET变量“content”传递
例如:
->?内容=contact.php
->?content=some/folder/这将打开
http://www.example.com/contact.php
而不是打开http://www.example.com
并设置content=contact.php
。您还有其他想法吗?这将打开http://www.example.com/contact.php
而不是打开http://www.example.com
并设置content=contact.php
。你有其他想法吗?正如你所说:“但我希望用户在URL字段中有以下内容:'问题是如果example.com/contact.php
打开文件/contact.php
,因为它存在,但它应该打开example.com/
并设置GET参数content=contact.php
。你可以放置所有文件在文件夹(例如“template/”)中,从index.php请求(template/?content)。请注意,使用GET变量作为include文件的路径可能会导致恶意用户的目录横向攻击。请参阅:我的index.php
位于/index.php
上,我的内容php文件位于/content/
中。我现在需要什么?