我已经search了这个问题,但我只能遇到真正具体的答案,似乎很难适应我的具体需求。 比方说,我试图重写的URL是这样的: http://www.example.org/test.php?whatever=something 我想重写它,看起来像这样: http://www.example.org/test/something 我该怎么做?
我有一个index.php处理所有的路由index.php?page = controller(简化)只是为了与视图分离的逻辑。 Options +FollowSymlinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([\w\d~%.:_\-]+)$ index.php?page=$1 [NC] 其中基本上: http://localhost/index.php?page = controller到 HTTP://本地主机/控制器/ 任何人都可以帮我添加重写 http:// localhost / controller / param / value / param / value (和soforth) 那将是: HTTP://本地主机/控制器/ PARAM =值&PARAM =值 我不能让它与重写软件一起工作。 一个控制器可能看起来像这样: <?php if (isset($_GET['action'])) { if ($_GET['action'] == 'delete') { do_Delete_stuff_here(); } } […]
我无法弄清楚为什么我的.htaccess头设置不起作用。 我的.htaccess文件内容: Header set Access-Control-Allow-Origin * Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT" Header always set Access-Control-Allow-Headers "*" RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php [QSA,L] 但是,当我删除Header的,并将其添加到index.php然后一切正常。 header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS"); header("Access-Control-Allow-Headers: *"); 我错过了什么?
我有我的.htaccess文件中的以下重写从文件中删除.php扩展名,例如so.com/question.php转换为so.com/question 。 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L] 但是,这也违反了默认的DirectoryIndex行为,只要input目录就会redirect到文件夹中的索引文件,例如so.com/answer显示so.com/answer/index.php 简单地将上面的代码与DirectoryIndex index.php结合起来并不能实现这两个结果。 有人可以帮助我结合这两个函数,或重写代码来排除index.php文件,这将实现相同的结果?
我上传了我的symfony2项目到服务器林。 主页面加载,但所有的链接被打破。 我尝试添加app.php的url。 它确实有效,但是: 我有像这样的路线: www.something.com/app.php/something 我希望他们成为: www.something.com/something。 我一直在阅读,我应该在.htaccess上写一些重写规则。 我发现了这些规则,但似乎并不奏效: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ app.php [QSA,L] </IfModule>
我从来没有使用过CodeIgniter,更不用说任何PHP框架,我想我会试试看。 一切都很好,除了我似乎无法从URL中删除index.php,仍然访问我的网页。 我从来没有使用MVC结构,所以我正在学习,所以如果我做错了,请原谅我。 我试图通过简单地inputlocalhost / ci / about访问我创build的名为'about_page.php'的视图,但是目前我只能通过使用localhost / ci / index.php / about 该页面的控制器是: /application/controllers/about.php 该页面的模型是: /application/models/about_model.php 而该页面的视图是: /application/views/about_page.php 我已经find了解决这个问题的方法,但一直没有find答案。 这是我已经搜查的地方: CodeIgniter – 删除index.php Codeigniter – 如何从url中删除index.php? http://www.farinspace.com/codeigniter-htaccess-file/ CodeIgniter在“应用程序”文件夹中提供了一个.htaccess文件,其中只包含“ Allow Deny From All 。 所以我在根目录下创build了一个新的.htaccess文件, http://localhost/ci/.htaccess并添加了这个代码: RewriteEngine On RewriteBase /ci RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] 当.htaccess文件位于根目录时,我得到一个500内部服务器错误。 当我将完全相同的文件复制到应用程序文件夹500错误消失,但我仍然无法通过使用localhost / ci […]
目前我正在使用光速服务器托pipe。 主机说mod_rewrite已启用,但我不能让我的脚本在那里工作。 每当我尝试访问的URL,它返回404 – 找不到页面。 我把相同的代码放在另一台运行Apache的服务器上。 在那边工作 所以我想,这是.htaccess和mod_rewrite问题。 但Hosting的支持仍然坚持,他们的mod_rewrite是打开的,所以我想知道如何检查它是否实际启用或不。 我试图检查与phpinfo() ,但没有运气,我找不到mod_rewrite在那里,是因为他们正在使用lightspeed ? 有什么方法可以检查吗? 请帮我一下 谢谢。 仅供参考:我的.htaccess代码是 Options -Indexes <IfModule mod_rewrite.c> DirectoryIndex index.php RewriteEngine on RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ ./index.php/$1 [L,QSA] </IfModule> 我也是这样试过的 DirectoryIndex index.php RewriteEngine on RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ ./index.php/$1 […]
我试图强制下载一个文件夹的所有文件。 页面上的链接如下所示 <a href="http://example.com/uploads/documents/file.pdf">Click to download</a> 我的.htaccess中有这个片段 <filesMatch ".*uploads/documents.*"> ForceType application/octet-stream Header set Content-Disposition attachment </filesMatch> 我已经知道标签内的2行工作,因为它的工作原理,当我把一个.htaccess直接在我想强制下载下面的代码文件夹: <Files *.*> ForceType application/octet-stream Header set Content-Disposition attachment </Files> 似乎有什么我不明白的filesMatch标签。
我正在尝试将https://www.example.comredirect到http://www.example.com 。 我在.htaccess文件中试过下面的代码 RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L] 此代码成功将https://example.comredirect到http://www.example.com 。 但是,当我inputhttps://www.example.com,然后在浏览器中给我一个“网页不可用”的错误。 我也尝试了以下两个代码没有成功 尝试1 RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^/(.*):NOSSL$ http://www.example.com/$1 [R=301,L] 尝试2 RewriteEngine On RewriteCond %{HTTPS} on RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} 上述两次尝试失败。 有什么build议么?
我无法从Codeigniter中的URL中删除index.php。 我用Codeigniter 1.7创build了一些网站,我用的.htaccess代码在2中不起作用。 我曾尝试使用 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ /index.php?/$1 [L] RewriteCond %{REQUEST_URI} ^application.* RewriteRule ^(.*)$ /index.php?/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] </IfModule> 和 <IfModule mod_rewrite.c> RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt|css) RewriteRule ^(.*)$ ./index.php/$1 [L] </IfModule> 我也试过没有RewriteBase /中。 我已经将$ config ['uri_protocol']更改为REQUEST_URI和QUERY_STRING,没有任何内容。 我已经设置了$ config […]