1

I am new one, I learn .htaccess. I want to customize my URL from index.php?page=mobile to index/page/mobile

I used this code but it doesn't work:

RewriteEngine on
RewriteRule    ^index/([0-9]+)/?$    index.php?page=$1    [NC,L]    # Handle product requests

and

RewriteEngine on
RewriteRule ^index/([^/.]+)/?$ index.php?page=$1 [L]
1
  • ^index/([^/.]+)/?$ won't match index/page/mobile. That expression only goes one level deep. Are you familiar with regexes? Commented Feb 19, 2014 at 21:20

3 Answers 3

7

This rule should work:

RewriteEngine on
RewriteBase /cashearn/

RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ index/page/%1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^index/page/([^/]+)/?$ index.php?page=$1 [L,QSA,NC]

This will let you have URL as http://domain.com/index/page/mobile on your page.

Sign up to request clarification or add additional context in comments.

5 Comments

zohaib wants "index" also in url
What is location of this .htaccess and what URL did you enter in browser?
This .htaccess file is located with index.php file
ok what is xxxxxxx here before index.php? Is this a folder?
yes folder its a web name which i run in localhost like localhost:1000/cashearn/index.php?page=mobile
2

Try that code:

RewriteEngine on
RewriteBase /
RewriteRule ^index/page/([^/.]+)/?$ index.php?page=$1 [L,QSA,NC]

1 Comment

Dear downvoter, can you tell why did you downvoted my answer?
0

This should work - not tested though

RewriteRule ^index/page/([^/.]+)$ index.php?page=$1 [L,QSA,NC]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.