Ok, i fixed all the problem, configured the server on localhost, but i want to hide the /public directory and want to display the content in the root folder of my document for example /forum/ and for logging /forum/login instead of going to forum/public/login. Here is the htaccess file but it dont work, because it gives No routes for GET /forum/.
RewriteEngine On
RewriteBase /forum/
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
What im doing wrong ?
Actually sometimes we may need to add .htaccess file
We can use this code as .htaccess file. I have checked this on Ubuntu VPS and also on Cpanel.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /index.php/
</IfModule>
</IfModule>
My root .htaccess looks like this, I think you can put it onto your symfony root folder.
# Removes index.php from ExpressionEngine URLs
RewriteEngine on
# RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*) /public/$1 [L]
Then my .htaccess inside the public/ folder:
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the index.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]
# Sets the HTTP_AUTHORIZATION header removed by Apache
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/index.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the start page because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
# Rewrite all other queries to the front controller.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
Related
I installed Codeigniter 4.0.0.rc3 on my local computer using Wampserver and created a 'people' controller. I can access the page using this address:
http://127.0.0.1/election/index.php/people
But not without 'index.php':
http://127.0.0.1/election/people
And this is the error:
The requested URL /Projects/Web/election/public/index.php/people was not found on this server.
.htaccess is in the public directory and is working because the error shows index.php in the path.
This is my htaccess:
# Disable directory browsing
Options All -Indexes
# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------
# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
# RewriteBase /
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to the front controller, index.php
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
# Disable server signature start
ServerSignature Off
# Disable server signature end
UPDATE: This htacces is working perfectly on a Linux Host but not working with Wampserver on Windows 10
In linux apache2 the following works, should be applicable to wampp's apache as well:
Make sure mode_rewrite is enabled
Edit your public .htaccess file as follows:
RewriteRule ^(.*)$ index.php/$1 [L]
to
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
(would appreciate if someone explains the QSA statement)
In app/Config/App.php edit:
public $indexPage = 'index.php';
to
public $indexPage = '';
I had to play around a lot before I figured it out, but I had installed CodeIgniter in a subfolder. (I access the website via http://127.0.0.1/myapp/).
I had configured the $baseURL parameter in the config file, but I kept getting that apache error. Just like you, if I added the /index.php in the URL, all my routes were working fine.
In /public/.htaccess, The QSA option didn't help, but this section just above did:
# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
RewriteBase /myapp/
Adding this allow mod_rewrite to work fine. Obviously you need to change /myappp/ to what your virtual subfolder is, in order for it to match the subfolder portion of the $baseURL parameter in Config/App.php
Hope this help !
Ok, vague question title, I know. Wasn't sure how to summarize this in one line. I have two applications in my CodeIgniter installation: frontend and admin. There are two front controllers for each that set to the correct application folder. Currently, I use index.php/home for the home page of the frontend and admin.php/home for the home page of the admin panel.
I finally got around to removing index.php from the URL of the frontend. For the admin cp, I would like to use example.com/admin instead of example.com/admin.php. So I basically need to rewrite any uri that has admin as the first segment to admin.php. I figured that adding RewriteRule ^admin/(.*)$ admin.php/$1 to my htaccess would do the trick, but apparently it doesn't... Not completely anyway. I get 404 Page Not Found for every single page in my admin cp. What am I doing wrong?
# Deny OR Allow Folder Indexes.
# Since we disable access to PHP files you
# can leave this on without worries.
# OR better yet, create a .htaccess file in
# the dir you want to allow browsing and
# set it to +Indexes
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
# mod_rewrite rules
RewriteEngine on
# The RewriteBase of the system (if you are using this sytem in a sub-folder).
# RewriteBase /CodeIgniter_1.6.3/
# This will make the site only accessible without the "www."
# (which will keep the subdomain-sensive config file happy)
# If you want the site to be accessed WITH the "www."
# comment-out the following two lines.
# RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
# RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
# If a controler can't be found - then issue a 404 error from PHP
# Error messages (via the "error" plugin)
# ErrorDocument 403 /index.php/403/
# ErrorDocument 404 /index.php/404/
# ErrorDocument 500 /index.php/500/
# Deny any people (or bots) from the following sites: (to stop spam comments)
# RewriteCond %{HTTP_REFERER} nienschanz\.ru [NC,OR]
# RewriteCond %{HTTP_REFERER} porn\.com
# RewriteRule .* - [F]
# Note: if you are having trouble from a certain URL just
# add it above to forbide all visitors from that site.
# You can also uncomment this if you know the IP:
# Deny from 192.168.1.1
# If the file is NOT the index.php file
RewriteCond %{REQUEST_FILENAME} !index.php
# Hide all PHP files so none can be accessed by HTTP
RewriteRule (.*)\.php$ index.php/$1
# If the file/dir is NOT real go to index
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
RewriteRule ^admin/(.*)$ admin.php/$1
</IfModule>
# If Mod_ewrite is NOT installed go to index.php
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
You need to add your rule before you index.php routing rule. It's because ^(.*)$ is matching admin/whatever, so your admin rule will never get executed. You should also add -Multiviews to your options so it looks like this:
Options +FollowSymLinks -Multiviews
Then right under RewriteEngine On, add your rule:
RewriteRule ^admin/(.*)$ admin.php/$1 [L]
I have Symfony2 installed in <host>/Symfony/ though with the default .htaccess in /var/www/Symfony/web/ when I go to:
<host>/Symfony/web/app.php/hello/James
I get redirected to:
<host>/hello/James
I want to get redirected to:
<host>/Symfony/hello/James
I think it is something to do with this in the .htaccess:
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule .? %{ENV:BASE}app.php [L]
I not very good with mod_rewrite
EDIT
# Use the front controller as index file. It serves as fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# startpage (path "/") because otherwise Apache will apply the rewritting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the startpage because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
# The following rewrites all other queries to the front controller. The
# condition ensures that if you are using Apache aliases to do mass virtual
# hosting, the base path will be prepended to allow proper resolution of the
# app.php file; it will work in non-aliased environments as well, providing
# a safe, one-size fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule .? %{ENV:BASE}app_dev.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the startpage to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
I am using Ubuntu 12.10. And I am having trouble removing the "index.php" from my codeigniter site URL.
My .htaccess files looks like this, I have my code inside hmvcExample folder.
*
RewriteEngine On
RewriteBase /hmvcExample/
### Canonicalize codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# Enforce www
# If you have subdomains, you can add them to
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]
# Enforce NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
###
# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
*
And my I have removed "index.php" from config.php as well. But I still get the following error when i try to load the site without "index.php"
Not Found
The requested URL /hmvcExample/signup was not found on this server.
Apache/2.2.22 (Ubuntu) Server at localhost Port 80
Please Help. Thanks.
This seems to be one of the question should have been looking for - How to remove "index.php" in codeigniter's path
And there is another config that you need to edit:
$config['uri_protocol'] = 'AUTO';
Change the line written above to the following:
$config['uri_protocol'] = 'REQUEST_URI';
If you have done all of this, there still might be one issue left - enable mod_rewrite
MAKE sure you have AllowOverride All set up in the /etc/httpd/conf/httpd.conf (centos apache 2.2)
config:
$config['index_page'] = '';
So I have a dilemma..
Can't figure out how to rewrite this URL to THIS URL:
URL=www.EXAMPLE.com/users/USERNAME
THIS URL= www.EXAMPLE.com/USERNAME
This isn't my first time using Stack Overflow, but this is my first time actually needing an account to find my answer. I will Thank accordingly.
Thanks,
Nick
EDIT:
RewriteRule ^user/(.*)$ /$1 [R=301,L]
But I get a 404 page, weird I say.
The page redirects successfully, but with a 404 instead.
HTACCESS as follows:
## Mod_rewrite in use.
RewriteEngine On
RewriteRule ^user/(.*)$ /$1 [R=301,L]
## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.
## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects
##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##
# RewriteBase /
## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
[UPDATE 4/08/13]
So after a while I have figured out that the only way an extension I am using works alongside Joomla! You need to use a separate extension called sh404sef to make this work. So in a nut shell, no use editing the HTACCESS file like I thought. Ended up spending the 40 bucks and it worked instantly. HAHA
This should answer your question
RewriteRule ^users/(.*)$ $1
Source: .htaccess rewrite from subdirectory to root
A site i find useful with .htaccess url rewriting is:
http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html
The example:
Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233
in browser you can see my profile over there. If you want to do the
same kind of redirection i.e http://yoursite.com/xyz to
http://yoursite.com/user.php?username=xyz then you can add the
following code to the .htaccess file.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
So in your case you could go for:
RewriteRule ^users/([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^users/([a-zA-Z0-9_-]+)/$ user.php?username=$1
see https://stackoverflow.com/questions/20610980/mod-rewrite-redirect-except-parked-domain
All www.primary.com go to www.primary.com/webtrees
Options -Indexes +SymLinksIfOwnerMatch
RewriteEngine on
RewriteBase /
RewriteCond $1 !^parked.com/
RewriteCond $1 !^piwik/
RewriteCond $1 !^wordpress/
RewriteCond $1 !^marker.htm
RewriteCond %{REQUEST_URI} !^/webtrees/
RewriteRule ^(.*)$ /webtrees/$1 [L]