-2

First case (dynamic links): I have a URL http://pqr.com/cms.php?PageId=MTE= and i want to convert this URL into http://pqr.com/hoiw-it-works. I have many links like i have mentioned earlier and i want to convert same way

Second case (static links): i have some static links like http://pqr.com/CustomerLogin.php so i want to convert this into http://pqr.com/login

Third case: i want to handle page not found case like following

  1. http://pqr.com/asasasa this is not in our website so it should redirect to either 404.php or index.php
  2. http://pqr.com/xyz.php if it is not found then it should redirect to either 404.php or index.php

can you provide me htaccess for this or is there any other way to rewrite url?

user3454835
  • 113
  • 1
  • 14
  • possible duplicate of [Reference: mod\_rewrite, URL rewriting and "pretty links" explained](http://stackoverflow.com/questions/20563772/reference-mod-rewrite-url-rewriting-and-pretty-links-explained) – deceze Apr 18 '14 at 07:34
  • Not got solution from there that is why i have created new question. i have already checked this – user3454835 Apr 18 '14 at 07:37
  • What particular part of your problem wasn't answered there? – deceze Apr 18 '14 at 07:39
  • Main thing is my problem was not solved from that link – user3454835 Apr 18 '14 at 07:40

1 Answers1

0

Use mod_rewrite.

To rewrite /login to /CustomerLogin.php, add the following to your .htaccess file:

RewriteEngine On
RewriteRule ^login/?$ CustomerLogin.php

This internally converts the URL the user sees to the one the server should see. If you additionally want to externall redirect users to /login if they call /CustomerLogin.php directly, add:

RewriteCond %{REQUEST_URI} ^/CustomerLogin\.php
RewriteRule ^.* /login [R,L]

Parameters may be passed too using mod_rewrite:

RewriteRule ^how-it-works/?$ cms.php?PageId=MTE [QSA]

But you need some method to figure out the right ID.

Callidior
  • 2,899
  • 2
  • 18
  • 28
  • dynamically it is not working. RewriteRule ^how-it-works/?$ cms.php?PageId=MTE [QSA] it should accept dynamic id – user3454835 Apr 18 '14 at 07:48
  • i can't sepcify for each single page – user3454835 Apr 18 '14 at 07:49
  • But there does the ID come from? You can't guess it from just having "how-it-works". So, you must either include the ID in your URL (e. g. `/how-it-works--PageID`) or redirect every request internally to a script that looks up the right ID corresponding to "how-it-works" and includes the respective script like many CMS do it. – Callidior Apr 18 '14 at 10:01
  • I have number of pages like cms.php?PageId=MTE but with different page id so i want to access each page by name like i access how-it-works page. please tell me best solution for this – user3454835 Apr 18 '14 at 11:24
  • Is this name stored in a database, so that you have *any* chance to associate the name with the respective ID? – Callidior Apr 18 '14 at 16:47