Does anyone have a simple way of rdirected in .htaccess all pages that were once .asp to now be .php. For example index.asp is now index.php etc. Server is apache.
RewriteEngine on
RewriteRule ^(.+)\.asp$ $1.php
Related
I want to redirect
https://example.com/index.php to https://example.com
https://example.com/view/india.php to https://example.com/india
https://example.com/view/city/india/chennai.php to https://example.com/india/chennai
this is what i want to acheive anyone please send me the .htaccess code for this problem.
You'll be using
RewriteEngine on
RewriteRule ^(.*)$ $1.php
I have somehow managed to redirect my site from domain.com/ to domiain.com/index and I was hoping someone could take a look at my .htaccess code to see where I have gone wrong.
Quick background story
I had an old website where all files were html
I then bundled all those files into a folder called old and told all
bots via robots.txt not to crawl it. robots.txt remains in the root
folder
A bunch of .php files were then added to the root folder. Each file has its own rel="canonical" tag with href="http://domain-name.com/file-name" - the homepage rel="canonical" ends with /index
Inside the root folder, I created a .htaccess file that:
Redirected .html files to the correct .php file
Redirect index.php to root (this does not seem to work)
Redirect www to non-www
Remove php file extension
I've tried to re-order the code in case I'm, for example, trying to remove extensions before properly redirecting but nothing seems to work.
I've tried playing around with how I'm redirecting index to index and nothing seems to work.
To see what the redirect path looks like I opened Chromes developer tools and selected network. From there I typed in
http://www.domain-name.com/index.html
And the redirect path looked like this
http://www.domain-name.com/index.html
http://domain-name.com/index.html
http://domain-name.com/index (this is my index.php file)
My htaccess code
301 Redirects Old HTML over to new PHP
Redirect 301 /index.html http://domain-name.com/index
Redirect 301 /about_us.html http://domain-name.com/about
Redirect 301 /services.html http://domain-name.com/services
Redirect index.php to root
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://domain-name.com/$1 [R=301,L]
Redirect www to non-www
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain-name\.com [NC]
RewriteRule ^(.*)$ http://domain-name.com/$1 [L,R=301]
</IfModule>
remove php file extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
I'm not sure what I have done wrong but I'm hoping you can help me understand why the homepage is redirecting to
http://domain-name.com/index
Thank you for your time
Change Redirect 301 /index.html http://domain-name.com/index
to Redirect 301 /index.html http://domain-name.com/
File index.php is your DirectoryIndex so request to http://domain-name.com/ load /index.php
If not, please add to top of your .htaccess file directive: DirectoryIndex index.php
How do I hide all subfolders from the URLs on my site?
So http://www.example.com/whatever just shows as http://www.example.com.
Just put this into you htaccess:
RewriteEngine On
RewriteRule ^ index.php [L]
All your request will be rewritten to index.php, which will achieves what you're describing.
I am using mod_rewrite in .htaccess to redirect from .php to .html like this:
RewriteRule ^([^.]+).html$ /$1.php [QSA,L]
It works in a web browser, but Google is crawling the old URLs i.e. index.php and faq.php.
How I can redirect the index.php to index.html? My website URL is: http://www.21flats.com/.
Add [QSA,L,R=301] so Google will see that there has been a redirect. This adds a 301 redirect to the rewrite for search engines:
RewriteRule ^(.*)\.php$ /$1.html [QSA,R=301,L]
You have the redirect backwards, so change it and add the 301 rule and you are good.
You can try something like this:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php [L]
i want to create with htaccess that if you go to www.website1.com/page.php that you go to www.website2.com/page.php, and www.website1.com/foo/bar/index.php to www.website2.com/foo/bar/index.php redirects. How can i do that with htaccess? Example please.
If mod_rewrite is available, you can put this code into the .htaccess of www.website1.com:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?website1\.com$
RewriteRule ^(.*)$ http://www.website2.com/$1 [L,QSA,R=301]
This would redirect every page on website1.com to the equivalent on website2.com