my site's directory is:
localhost/
includes/
includes/initialize.php
includes/user.php
includes/session.php
includes/database.php
public/
public/bootstrap/
public/css/
public/js/
public/dashboard/index.php
public/index.php
.htaccess(first htaccess file)
{
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1 [QSA,L]
</IfModule>
}
I'd like to have my url more neat, for example
when I type this: http://localhost I know it goes to http://localhost/public/
but the URL still is http://localhost
but the problem is when I type http://localhost/dashboard
unfortunately the URL will be http://localhost/public/dashboard/ on my browser.
I do not want to see the word public.
I think I should have another htaccess file under the public directory, but I do not know the suitable code for it.
Try this code in your DOCUMENT_ROOT/.htaccess file:
DirectoryIndex index.html index.php
RewriteEngine On
RewriteRule !^public/ /public%{REQUEST_URI} [NC,L]
Related
i want to change my permalink example www.testing.com/1234/"titlename" instead of www.testing.com/1234/, how to do i change it through .htaccess? Below are my .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /clients/ohmynews/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?article/([a-zA-Z0-9_-]+)$ detail.php?did=$1
RewriteRule ^/?([a-zA-Z0-9_-]+)$ listing.php?lid=$1
RewriteRule ^/?search/([a-zA-Z0-9_-]+)$ search.php?keys=$1
DirectoryIndex index.php
ErrorDocument 404 http://wipstage.com/clients/ohmynews/web/
</IfModule>
Include this line into your htaccess file:
RewriteRule ^([0-9]+)/([A-Za-z0-9._-]+)/?$ detail.php?id=$1&title=$2
As i do not know your actual running file path, so make sure you put your original running file path in my code.
Or let me know your file name with location, i will edit my answer.
I tried to search and use the solutions already posted but nothing worked for now and I tried pretty much everything I could but didn't work.
These are the app directories:
localhost/
root/
data/
app/
public/
index.php
.htaccess
The htaccess is this:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /root/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
The first problem is that if I go to localhost/root/public the website works as intended but in the url I still see 'public' which I'd like to remove.
The second problem is that my objective is to go to the index from the url localhost/root/ but now, if I go there it just shows the files in the folder.
Thank you.
As requested, these are the routes that I use:
$app->get('/', function () use ($app) {
// code
})->bind('home');
$app->get('/about-me', function () use ($app) {
// code
})->bind('about-me');
There are two mistakes in your system.
First:
The .htaccess located in the root folder should be used to remove the 'public' part of the URL. The code for that is like the following:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
It basically grabs every route and redirects it to the public folder, exactly as you wished!
Second:
You should create another .htaccess file in your '/public' folder to redirect everything to the index.php file. The code for that should look like this:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
You should end up with the following structure:
localhost/
root/
.htaccess (removes 'public')
data/
app/
public/
index.php
.htaccess (forward to index.php)
This should solve both your problems. If it does, please mark the question as completed by marking my answer as the one that solved it. If it does not, please comment on other problems that occur to you!
My htaccess is this :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([0-9a-zA-Z-]+)?$ show.php?id=$1 [L]
</IfModule>
So whenever browser get 'any thing' after root folder then it will go show.php and parameter will be 'any thing' .
Note: it will not effect if it have extension or a folder.
But there is index file in my root folder. So browser should take index file first. So that, i added this in .htaccess file :
DirectoryIndex index.php
But not working. So is there anything to do, to show at least index file whenever root folder visited ?
You can have your .htaccess like this:
DirectoryIndex index.php
RewriteEngine On
# request is not for a file
RewriteCond %{REQUEST_FILENAME} !-f
# request is not for a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z-]+)/?$ /show.php?id=$1 [L,QSA]
Can any one help me in .htaccess.
My use case is, if there is index.php in the directory http://domain_name/user/ then load index.php else set rewriteRule to call forbidden.php.
I did a bit but not succeed yet. .htaccess code on my server is-
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond ^(.*)$/index.php !-d
RewriteCond %{REQUEST_URI} (.*)/$
RewriteRule ^(.*)$ forbidden.php?handle=$1
</IfModule>
I think there is an easier way to do what you want. There is no need for rewriting, simply define which page acts as the entry page. In the .htaccess file you can define:
DirectoryIndex index.php
ErrorDocument 404 /forbidden.html
Now, if anybody calls your directory http://www.example.com/user/, the page http://www.example.com/user/index.php will be shown.
If the file index.html does not exist, the server will return an error, so you can define an appropriate error page. With a leading /, you can define a single error page in the root directory, without the / it will look in the relative directory http://www.example.com/user/forbidden.php.
I have strange for me problem. I'm developing Zend Framework application and have this file structure:
/
/application/
/public/
/public/.htaccess
/public/index.php
/public/js/
/public/style/
/public/profile/
/.htaccess
My domain point to folder /
When I enter the address example.com/profile/ it goes to the controller profile and this is good.
When I enter the address example.com/profile the server redirects me to:
example.com/public/profile/
I would like to have a solution that whenever I request:
example.com/profile/ or
example.com/profile
The same page will be rendered but second version gives me a redirect and I don't know why.
The /.htaccess file is:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
The role of this file is to route all traffic from / to /public but without any redirects.
The /public/.htaccess file is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Can anybody help me with this? Thanks.
I fixed this. Here is the solution if somebody have the same problem:
To fix this you have to set the following options and disable DirectorySlash
Options -Indexes FollowSymLinks
DirectorySlash Off
Now Apache shouldn't add trailing slashes at the end of uri when you pointing to directory.
This also disable redirect to the uri with trailing slash.
Optionally match the last /. Change your .htaccess file to this:
RewriteEngine On
RewriteRule ^(.*)/?$ public/$1 [L]
This works for me:
RewriteEngine On
RewriteRule ^/$|^(.*)$ /public/$1 [QSA,NC,L]