I would like to change "/" to "/folder".
So when user clicks link with this url "/page.php" I want it to be automatically translated by .htaccess to "/folder/page.php".
How can I achieve this?
This simple rule should work for you in site root .htaccess (parent directory of folder):
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder/ [NC]
RewriteRule .* folder/$0 [L]
Please use .htaccess file. i think its better for you.
Your Need is:
HTTP://YOUR_DOMAIN.COM/page.php
TO
HTTP://YOUR_DOMAIN.COM/FOLDER/page.php
Step1:
create an .htaccess file on your Server
Filename: .htaccess
just Copy this part and Change the Values.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} YOUR_DOMAIN.COM$ [NC]
RewriteCond %{HTTP_HOST} !FOLDER
RewriteRule ^(.*)$ http://YOUR_DOMAIN.COM/FOLDER/$1 [R=301,L]
Reference-1 |
Reference-2
Try this:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder/$1 [QSA,PT,L]
RewriteRule ^$ /folder/$1 [QSA,PT,L]
RewriteRule ^index.php/(.*) $1 [QSA,R,L]
</IfModule>
Related
I am using an AWS EC2 instance to host a website. I have an installation under /var/www/html/xyz/ dir & thus if I have to access website homepage, I have to specify link as www.example.come/xyz. I want that www.example.com should be redirected to www.example.com/xyz
Any idea how can I redirect www.example.com to www.example.com/xyz automatically (httpd config or anything similar)?
I checked online but most of the posts are related to subdomain redirects e.g. redirect admin.example.com to www.example.com which is not my issue.
Thanks!
my .htaccess file is:
<IfModule mod_rewrite.c>
RewriteEngine on
# Some hostings require RewriteBase to be uncommented
# Example:
# Your url is http://www.yourcompany.com/xyz
# So "RewriteBase" should be:
# RewriteBase /xyz
Options -MultiViews
RewriteBase /xyz
RewriteCond %{REQUEST_URI} ^api/(.*)$ [or]
RewriteCond %{REQUEST_URI} .*/api/(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*api/(.*)$ api.php?_d=$1 [L,QSA]
RewriteCond %{REQUEST_URI} \.(png|gif|ico|swf|jpe?g|js|css|ttf|svg|eot|woff|yml|xml)$ [or]
RewriteCond %{REQUEST_URI} store_closed.html$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)\/(.*)$ $2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L,QSA]
</IfModule>
Another option is to change the document root of your site. If you are running Ubuntu, you should have a file in /etc/apache2/sites-available/YOUR_SITE.conf (maybe default.conf). Just edit it and change the DocumentRoot to point to your subfolder.
Create new .htaccess file with following code
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) /xyz/ [R=301]
you should have mod_rewrite enabled.
Use this code in your htaccess file, this will redirect the user to the subfolder without changing th URL www.domain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteRule !^subdir/ /subdir%{REQUEST_URI} [L,NC]
Another method with URL www.domain.com/subdir
RewriteEngine On
RewriteRule ^$ /subdir[L]
You can use the following code in Root/.htaccess:
RedirectMatch ^/$ /xyz
This will redirect
http://example.com
to
http://example.com/xyz
And you want to Rewrite http://example.com/foo to http://example.com/xyz/foo , you can use mod_rewrite :
RewriteEngine on
RewriteRule ^/?((?!xyz).*)$ /xyz/$1 [L]
Hope this will help !
RewriteEngine on
RewriteCond %{HTTP_HOST} domain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /subfolder/$1 [L]
or this
Redirect 301 /path/to-old-url http://www.cyourdomain.com/path/to-Try this new-url
I have some configuration in htaccess:
RewriteEngine On
RewriteRule ^(.*)$ /index.php [L,NC,QSA]
All urls redirects to /index.php
But if folder exists, it goes to folder, not to /index.php
why?
I tried this solution to make this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . index.php [QSA,L]
But this like a previously example goes to directory =(
Try this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php
Or
RewriteEngine On
RewriteCond %{REQUEST_URI} !-f
RewriteRule (.*) index.php [QSA]
Use something like this:
#turn rewrite engine on
RewriteEngine On
#specify your base
RewriteBase /
#make sure, your index.php won't be rewritten
RewriteRule ^index.php - [L]
#rewrite everything else
RewriteRule ^(.*)$ index.php?para=$1 [QSA,L]
But if folder exists, it goes to folder, not to /index.php
Try disabling MultiViews – it is often interfering in such cases.
Options -MultiViews
http://httpd.apache.org/docs/2.2/mod/core.html#options
http://httpd.apache.org/docs/2.2/mod/mod_negotiation.html#multiviews
i got a problem with rewriting my edit.php?id=1 to edit/id/1. Right now i have the following in my .htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^edit/id/([^/.]+)$ edit.php?id=$1 [NC]
This doesn't change the url. Can something see what i do wrong?
You need one additional rule to change the URL externally. This should be placed in root .htaccess:
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/([^/]+)/edit\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1/edit/id/%2? [R=302,L,NE]
RewriteRule ^([^/]+)/edit/id/([^/.]+)$ $1/edit.php?id=$2 [NC,L,QSA]
Give this a try and see how it works for you.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/edit/id/([^/.]+)$ $1/edit.php?id=$2 [NC,L]
</IfModule>
OR you can do this if you only have a couple of directories the same. The will go in the root .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(profiles|customers|test)/edit/id/([^/.]+)$ $1/edit.php?id=$2 [NC,L]
</IfModule>
This is where the PHP files are:
ts1.WEBSITENAMEHERE.biz/cp/
The .htaccess file is also in this folder.
I want to remove the '.php' from 'FILENAME.PHP'.
This is my current '.htaccess' file:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /cp
RewriteRule ^(.*)/$ $1.php
But it is not working. Why is this?
RewriteEngine on
RewriteBase /cp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.php$
RewriteRule .* $0.php [L]
Create a .htaccess file in the DocumentRoot dir.
Add the following code in that file...
##############
RewriteEngine On
RewriteCond %{REQUEST_URI} !^(.*)\.(.*)$
RewriteRule ^(.*)$ %{REQUEST_URI}.php [R]
#############
mod_rewrite should be enabled for this to work.
Options +FollowSymlinks
RewriteEngine on
RewriteBase /cp
RewriteRule ^(.*) $1.php
I use this checker: http://htaccess.madewithlove.be
The main site runs WordPress with .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I'm going to create an CodeIgniter app in subdirectory site.com/online/
If simply add CI .hta file in subfolder it wouldn't work. CI .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|img|styles|js)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Is it possible to combine two .htaccess files or to do something with .htaccess in CI subfolder?
Thank you.
UPD.
Thank you for answers, I've tried all variants, and eventually moved project to subdomain.
First thing, your .htaccess should be like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} !^GET\s/+online/ [NC]
RewriteRule . /index.php [L]
</IfModule>
#Then add this for CI handling in the same .htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !index\.php [NC]
RewriteRule ^online/(.*)$ online/index.php?/$1 [L,NC]
Then you can remove (or rename) .htaccess in the online subfolder.
Try this for the codeigniter .htaccess:
RewriteEngine on
RewriteBase /online
RewriteCond $1 !^(index\.php|robots\.txt|img|styles|js)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Otherwise all requests to that subfolder would be redirected down to wordpress.
Are you setting AllowOverride? According to the docs you need to allow FileInfo overrides for mod_rewrite.