How to rewrite the urls using .htaccess file in website dynamically

I created new website recently. I wanted to utilize the .htaccess. can you suggest how to use .htaccess. I had old website, which I wanted those urls to redirect new website.

 

.




 

1. redirecting different error pages to index.php

ExpiresActive on
ExpiresDefault M86400
ErrorDocument 400 /index.php
ErrorDocument 401 /index.php
ErrorDocument 403 /index.php
ErrorDocument 500 /index.php

2. Create 404 page and redirect to 404 error to "404.php" page.
Whenver user types wrong url, it will create 404 error code. So to avoid this confusion and to create the comminication to the user, Need to create 404 page with search page where user can search and find relative page.

ErrorDocument 404 /404.php

3. Redirect page from old to new page.

Redirect permanent //TCP_IP.htm /TCP_IP.php

4. Redirect all users to access the site with the 'www.' prefix

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} !.([a-z-]+.[a-z]{2,6})$ [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+..+.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}.txt(?: Comodo DCV)?$
RewriteCond %{REQUEST_URI} !^/.well-known/pki-validation/[A-F0-9]{32}.txt(?: Comodo DCV)?$
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} ^javavillage.in$ [NC] 
RewriteCond %{REQUEST_URI} !^/[0-9]+..+.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}.txt(?: Comodo DCV)?$
RewriteCond %{REQUEST_URI} !^/.well-known/pki-validation/[A-F0-9]{32}.txt(?: Comodo DCV)?$
RewriteRule ^.*$ http://www.javavillage.in%{REQUEST_URI} [R=301,L]

5. compress text, html, javascript, css, xml:

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp

6. Direct a page dynamically

RewriteRule ^view-topic.php(.*)$ http://www.walnutpost.com/view-topic.php$1

ex: http://www.javavillage.in/view-topic.php?tag=spring-vs-ejb if user for search for this will direct to http://www.walnutpost.com/view-topic.php?tag=spring-vs-ejb
Note: You should configure in javavillage.in .htaccess.

 
Post a Reply
Captcha Image