how to perform url rewriting using HTACCESS in server - .htaccess

I have the following .htaccess file
Options +FollowSymLinks
RewriteEngine On
Options -Indexes
RewriteRule ^index/?$ index1.php [NC]
RewriteRule ^index/(.*\.html)/?$ index1.php?load=$1 [NC,L]
RewriteRule ^page/?$ page.php [NC]
RewriteRule ^page/([0-9]+)/([a-z]+)/([{a-z}{0-9}{\-\}]+)/?$ page.php?id=$1&cat=$2&title=$3 [NC,L]
and its work perfectly in my localhost. but not works in server,
the following .htaccess works good in my server
RewriteEngine on
RewriteRule testpage\.html http://www.google.com [R]
did i make any mistake? any help?

Related

Redirection through .htaccess

I am developing a PHP website and I want to redirect php to html and I write the below code in htaccess file. Code is working fine and all the php pages are redirect to html but when I put file name with php in url site is also open with .
RewriteRule ^(.*)\.html$ $1.php [nc]
Replace your code with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[?\s] [NC]
RewriteRule ^ /%1.html [R=301,L]
RewriteRule ^(.+?)\.html$ /$1.php [L,NC]

Localhost htaccess is not working

I am using .htaccess file on my localhost and write this code:
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^about/?$ about.php [NC,L]
I have checked http.doc file everthing is fine. But its not working fine.
Thanks.
You can put the .htaccess on the www folder and place the content on it:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*)\.php [NC]
RewriteRule ^ /%1.html? [R=302,L]
RewriteRule ^abc/about\.html/?$ /abc/about.php [NC,L]

htaccess file working fine on local but on server error

This is my url http://www.example.com/demo/
what's wrong with my htaccess file? and how to slove it?
thank you in advance
#CHECK MOD REWRITE ON IN HOSTING SERVER
Options +FollowSymLinks
RewriteEngine on
#REWRITE URL FOR ALL PHP FILE TO HTML
RewriteBase /demo/
RewriteRule ^home\.html$ index.php?page=$1&lang=$2 [NC,L]
RewriteRule ^h([a-zA-Z0-9\-_\.\/]+)-([a-zA-Z0-9\-_\.\/]+)\.html$ index.php?page=$1&lang=$2 [NC,L]
RewriteRule ^p([a-zA-Z0-9\-_\.\/]+)-([a-zA-Z0-9\-_\.\/]+)\.html$ product.php?page=$1&lang=$2 [NC,L]
RewriteRule ^s([a-zA-Z0-9\-_\.\/]+)-([a-zA-Z0-9\-_\.\/]+)\.html$ service.php?page=$1&lang=$2 [NC,L]
RewriteRule ^a([a-zA-Z0-9\-_\.\/]+)-([a-zA-Z0-9\-_\.\/]+)\.html$ about.php?page=$1&lang=$2 [NC,L]
RewriteRule ^c([a-zA-Z0-9\-_\.\/]+)-([a-zA-Z0-9\-_\.\/]+)\.html$ contact.php?page=$1&lang=$2 [NC,L]

htaccess redirection and rewrite from php to html

I am stuck with .htaccess modification, need a little help.
First off, here is whats inside my htaccess.
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]
For example, I created the file named test.php and uploaded to my server.
I want my server to behave like this.
http://example.com/test/test.html -> http://example.com/test/test.html(as it is)
http://example.com/test/test.php -> http://example.com/test/test.html
but with the .htaccess I have right now,
I still have both .php and .html which may be considered as file duplication by search engine crawler like Google robot (isn't it?).
Any help appreciated.
try this .htaccess code
# Enable Rewrite Engine
RewriteEngine on
#Create friendly URL
RewriteRule ^test/(.*)\.html$ test/$1\.php [L]
OR
RewriteCond %{REQUEST_URI} ^(.*)\.php$
RewriteRule ^(.*) /$1.html [L]
OR
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## .php to .html
# To externally redirect /test/test.php to /test/test.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1.html [R,L,NC]
This is a configuration file of apache '.htaccess' if you still want to configure then change
RewriteEngine on
I hope this work
You may try this in one .htaccess file in root directory:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !\.html [NC]
RewriteRule ^([^/]+)/([^.]+)\.php /$1/$2.html [R=301,NC,L]
For silent mapping, replace [R=301,NC,L] with [NC,L]

Having issues redirecting in .htaccess

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]

Resources