With .htaccess how can i redirect:
http://localhost/mvc_md/index.php/welcome/destroy
to
http://localhost/mvc_md/welcome/destroy
I'm currently using this and it isnt working:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^localhost/mvc_md/$
RewriteRule ^(.*) localhost/$1 [QSA,L,R=301]
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-zA-Z]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?$ index.php/$1/$2/$3 [NC,L]
Related
I am trying to do two things here:
redirect to a sub-folder
redirect http://www.something.com/some/page.html
or
https://www.something.com/some/page.html
to
https://www.something.com/subfolder/some/page.html
redirect http to https
redirect
http://www.something.com/subfolder/some/page.html
to
https://www.something.com/subfolder/some/page.html
And I want to do both of them in the same .htaccess file
I have been able to redirect to subfolder by the following code:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} something.com [NC]
RewriteRule ^(.*)$ https://www.something.com/subfolder/$1 [R=301,NC]
And then I am trying to do both of them; i.e. http to https(only if http request comes) and redirect to subfolder by the following code:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteCond %{HTTP_HOST} something.com [NC]
RewriteRule ^(.*)$ https://www.something.com/subfolder/$1 [R=301,NC]
But it's not working.
What am I doing wrong here?
EDIT
When using #starkeen's solution; i.e.
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R]
RewriteCond %{REQUEST_URI} !^/subfolder
RewriteRule ^(.*)$ https://www.example.com/subfolder/$1 [R=301,NC,L]
I am expecting the following as result:
https://www.example.com/subfolder/brands/omega.html
when I give any of the following:
http://example.com/brands/omega.html OK
https://example.com/brands/omega.html OK
http://www.example.com/brands/omega.html OK
https://www.example.com/brands/omega.html OK
http://example.com/subfolder/brands/omega.html WRONG
http://www.example.com/subfolder/brands/omega.html WRONG
But the last two are redirecting to
https://www.example.com/subfolder/
Here is a rule to do both the tasks in a single rule:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{REQUEST_URI} !^/subfolder [NC]
RewriteRule ^(?:subfolder)?(/.*)?$ https://www.example.com/subfolder$1 [NE,L,R=302,NC]
Make sure to clear your browser cache before testing this rule.
Try :
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
#--Http ==>https--#
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R]
#--exclude the destination to avoid redirect loop--#
RewriteCond %{REQUEST_URI} !^/subfolder
#--redirect /foo to /subfolder/foo--#
RewriteRule ^(.*)$ https://www.something.com/subfolder/$1 [R=301,NC,L]
Clear your browser'cache before testing this redirect.
I would like to redirect my pages in the following ways:
www.example.com/index.cfm?locale=it -> www.example.com/it
and I would like to access the same page when I type:
www.example.com/it
I wrote an htaccess file but it causes a redirect loop. Here is the file:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#REWRITE RULES
#---------------------
RewriteCond %{QUERY_STRING} ^locale=(it|en|fr|de|es)$
RewriteRule ^index\.cfm$ %1? [R=302,L]
RewriteCond %{REQUEST_URI} !^index\.cfm
RewriteRule ^(it|en|fr|de|es)/?$ index.cfm?locale=$1 [L]
</IfModule>
Could you help me to resolve it?
Thanks!!!
You can try it this way.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
Rewrite ^ - [L]
RewriteCond %{THE_REQUEST} ^GET\ /index\.cfm\?locale=(it|en|fr|de|es)
RewriteRule ^ %1? [R=302,L]
RewriteRule ^(it|en|fr|de|es)/?$ index.cfm?locale=$1 [L]
Try this:
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com/it[nc]
RewriteRule ^(.*)$ http://www.example.com/it/$1 [r=301,nc]
//301 Redirect Old File
Redirect 301 www.example.com/index.php?locale=it www.example.com/it
//301 Redirect Entire Directory
RedirectMatch 301 www.example.com/index.php?locale=it(.*) www.example.com/it/$1
Currently my localhost URL is like localhost/apnaujjain/page.php?page_id=1&action=contacts
Now I want to write a rule so that when I go to above url it just rewrite the url like localhost/apnaujjain/contacts.html
See it should convert .php into .html without affect page content.
Until now I've tried
Options +FollowSymLinks -MultiViews
RewriteEngine on
#RewriteBase /
RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.php?page_id=1$&action=2$
RewriteRule ^(.*)\.php $2.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]
But it's not working.
You can use this code in /apnaujjain/.htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /apnaujjain/
# redirect localhost/apnaujjain/page.php?page_id=1&action=contacts to
# localhost/apnaujjain/1/contacts.html
RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&action=([^\s&]+) [NC]
RewriteRule . %1/%2.html? [R=301,L]
RewriteRule ^([^/]+)/([^.]+)\.html$ page.php?page_id=$1&action=$2 [NC,L,QSA]
I want to be able to redirect this URL:
www.shorturl.co.uk/answers
To this URL:
http://actual.url.co.uk/answers.html
I have tried the following in .htaccess but it doesn't appear to be working:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.shorturl\.co.uk$ [NC]
RewriteRule ^answers$ http://actual.url.co.uk/answers.html [L,R=301,NC]
Can anyone point out where I might be going wrong? Thanks
I'm not an expert in this, but you could give it a try:
RewriteCond %{HTTP_HOST} ^www\.shorturl\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^shorturl\.co\.uk$
RewriteRule ^answers$ http://actual.url.co.uk/answers.html [R=301,L]
I'm new htaccess. So i need to rewrite .php to .html in url.
my files located in
http://www.domain.us/sub1/sub2/sub2/index.php
I need to rewrite as
http://www.domain.us/sub1/sub2/sub2/index.html.
I tried something
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} site
RewriteRule ^(.*)\.php$ http://www.domain.us/sub1/sub2/sub3/$1.html [R,L]
But It shows 404 error.
Thanks.
Put this code in your DOCUMENT_ROOT's .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\s/*sub1/sub2/sub2/.*\.php [NC]
RewriteRule ^(.*)\.php$ /$1.html [NC,NE,R=301,L]