Showing posts with label htaccess. Show all posts
Showing posts with label htaccess. Show all posts

htaccess clean url php

htaccess clean url php

htaccess clean url php htaccess is the page url redirect and custom url is secure in web pages and passing data another page. follow us.

htaccess clean url php
htaccess clean url php

Redirect a dynamic redirect page

RewriteEngine On RewriteRule keyword/(.*).html keyword.php?page=$1

Page Redirect


Common variable sets

[A-Z] The variable can have uppercase letters
[a-z] The variable can have lowercase letters
[0-9] The variable can have numbers
([a-zA-Z0-9]+) The variable can have any of the above, and has no limit to the number of characters.

RewriteEngine On RewriteRule ^([a-zA-Z0-9]+)$ index.php?page=$1 RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page=$1

url pass multiple variables on .htaccess

 In this post I want to explain about URLs rewriting techniques using .htaccess file. Friendly URLs looks neat on the browser address bar.



RewriteRule extraurl/(.*).html currentsite.php?id=$1 [L,QSA]

RewriteRule ^extraurl/(.*).html subayurveda.php?aid=$1 [L,QSA]

url pass multiple variable
 url pass multiple variables on .htaccess


RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?keys=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?keys=$1


<?php

$keys=$_GET['keys'];

if($keys=='home')
{
include('home.php'); // Home page
}
else if($keys=='login')
{
include('login.php'); // Login page
else if($keys=='terms')
{
include('terms.php'); // Terms page
}
else 
{
include('users.php'); // Users Gateway
}
?>

Multipul Value:

htaccess code:

RewriteRule ^([\da-z]+)/([\da-z]+)/(\d+)/?$ index.php?category=$2&language=$1&id=$3 [L,QSA,NC]
RewriteRule ^([\da-z]+)/([\da-z]+)/?$ index.php?category=$2&language=$1 [L,QSA,NC]

php code:

print($_REQUEST);
exit;

output:

category = Value and Language = Value and id






USING .HTACCESS FILES

USING .HTACCESS FILES

INTRODUCTION

The .htaccess file is a powerful tool for modifying your Apache configuration on a per-domain and even a per-directory level. Many content management systems rely on .htaccess files for configuring your site. You can also create your own .htaccess file manually.

CREATING THE .HTACCESS FILE

Your .htaccess file needs to be a plain text file. This means you need to make it in a text editing program capable of producing plain text files.
  • On a Windows machine, you can use Notepad, which is one of your built-in accessories.
  • On a Mac, you can use TextEdit. You must first open the TextEdit "Preferences" menu and, in the "New Document" section, select "Plain text." Then, you can start a new document in TextEdit for your .htaccess file.
When you save your document, make sure you name it htaccess.txt, or something similar. If you save it as .htaccess, your computer will hide the file. This is because files that start with "." are considered to be system files.
htaccess set expiry of js

htaccess set expiry of js

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 7 days"
ExpiresByType image/jpeg "access 7 days"
ExpiresByType image/gif "access 7 days"
ExpiresByType image/png "access 7 days"
ExpiresByType text/css "access 7 days"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>


Set Cookie using htaccess

Set Cookie using htaccess

Header set Set-Cookie "language=%{lang}e; path=/;" env=lang

Set Cookie based on Request. This code sends the Set-Cookie header to create a cookie on the client with the value of a matching item in 2nd parentheses.

RewriteEngine On
RewriteBase /

RewriteRule ^(.*)(de|es|fr|it|ja|ru|en)/$ - [co=lang:$2:.yourserver.com:7200:/]


Custom Error Pages for Better SEO

Custom Error Pages for Better SEO

One use of the .htaccess file is to redirect users to a custom error page depending on the specific web server error they encounter. By using a custom error page, you can present them with a list of your site’s top articles, a sitemap with links to the various areas of your site, and it can include your site’s navigation system. It can also feature a FAQ, so folks who are looking for information on your site, but can’t find it, are able to narrow down the location of that information on your site without leaving, going back to the search engine, and more than likely not returning to your site.

It’s not difficult to use the .htaccess file to redirect users to a custom error page–but to do it you’ll need to know the proper error code. The most common ones you’ll use are:
  • 400 – Bad request
  • 401 – Authorization Required
  • 403 – Forbidden
  • 404 – File Not Found
  • 500 – Internal Server Error
To use .htaccess with these codes, first you’ll need to open up your favorite text editor, create a new document, and in that document, specify the error message that you’ll be redirecting like this:

ErrorDocument 404 /filenotfound.html

If you wanted to redirect users for another error, such as 500, Internal Server Error, you would do it like this (and so on):

ErrorDocument 500 /servererror.html

Then you’d just save the .htaccess file (remembering to check that it is
 saved just like that, without some additional extension), and upload it
 to your web host’s root directory (or whatever directory you are 
wanting to use it in).