Home > database >  How to url-redirection via .htaccess
How to url-redirection via .htaccess

Time:09-02

i am working with php,Right now i my current URL/domain something like "abc.com/project",But i want to pass query string with URL, in other words whenever anyone hit in this URL then URL should redirect with "query string" via .ht access,How can i do this ? Right now here is my " .htaccess" file

    RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?test/(.*?)/?$ /test.php?whatever=$1 [L]

CodePudding user response:

301 (Permanent) Redirect:
Use a 301 redirect .htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain.

When adding the following to your website's .htaccess file, be sure to replace example.com with your own domain name.

# This allows you to redirect your entire website to any other domain
Redirect 301 / http://example.com/
 
302 (Temporary) Redirect:
Point an entire site to a different temporary URL. This is useful for SEO purposes when you have a temporary landing page and plan to switch back to your main landing page at a later date:

# This allows you to redirect your entire website to any other domain
Redirect 302 / http://example.com/
 
Redirect index.html to a specific subfolder:
# This allows you to redirect index.html to a specific subfolder
Redirect /index.html http://example.com/newdirectory/
 
Redirect an old directory to a new directory:
# Redirects example.com/old to example.com/new
RewriteRule ^old/(.*)$ /new/$1 [R=301,NC,L]
 
Redirect an old file to a new file path:
# Redirect old file path to new file path
Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html
 
Redirect to a subfolder with URL masking:
# Show the content in example.com/folder2, but the URL appears as example.com/folder1
RewriteEngine On
RewriteRule ^folder1/?$ /folder2/

# To show the URL as just example.com
RewriteEngine On
RewriteRule ^/?$ /folder2/
 
Redirect to a specific index page:
# Provide Specific Index Page (Set the default handler)
DirectoryIndex index.html
 
Redirect an error message:
Instead of prompting a 404 Not Found error page, the site will redirect to the homepage:

# Redirect 404 Error pages to the home page
ErrorDocument 404 http://example.com/
 
Redirect a non-existing page to index.php
# Redirect non-existing pages to index.php
Options  SymLinksIfOwnerMatch 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

CodePudding user response:

if you want to redirect a URL or the same URL, you just need to know if your website has WordPress installed then it is very easy by using plugins but if it is a normal website then you need redirect generator tools (many available on google) or need a developer that writes your redirect code. you just copied it and paste it in the Cpanel-->your required website--->and some specific folder. you can follow the initial steps and a little bit of search can solve your problem.

redirect 301

Regards \\Zayyan.

  • Related