S
S
SkvPavel2014-09-16 11:41:11
PHP
SkvPavel, 2014-09-16 11:41:11

How to setup .htaccess to hide index.php?

There is an API, now it looks like this: somewww.ww/index.php/bla/bla
How to remove index.php from it? You need to make it look like this: somewww.ww/bla/bla
Thank you

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Volintsev, 2014-09-16
@SkvPavel

You need to do the opposite - redirect all URLs to index.php
For example, somewww.ww/bla/bla

# .htaccess

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$  index.php?query=$1

<?php
/**
 * index.php
*/
echo $_SERVER['QUERY_STRING']; // => 'query=/bla/bla' преобразованный URI
echo $_SERVER['REQUEST_URI']; // => '/bla/bla' оригинальный URI
var_export($_GET); // => array('query' => '/bla/bla')

D
Dmitry, 2014-09-16
@mytmid

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} (index.php|index.php/)(.*)$ [NC]
RewriteRule ^(index.php|index.php/)(.*)$ $2 [L,R=301]

How to properly issue a Redirect 301?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question