Hi
I want to use htaccess rewrite, which will act as below
1. http://mysite.com/?sura=x as http://mysite.com/x
2. http://mysite.com/?sura=x as http://mysite.com/x/
3. http://mysite.com/?sura=x&ayat=y as http://mysite.com/x/y
4. http://mysite.com/?sura=x&ayat=y as http://mysite.com/x/y/
is it possible by htaccess ??
please help me

Recommended Answers

Yes, it is possible. Here is a nice little htaccess rewrite generator that can write it for you too :)

http://www.generateit.net/mod-rewrite/

Jump to Post

try this:

RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)$ /?sura=$1&ayat=$2 [L]
RewriteRule ^([a-zA-Z0-9-]+)$ /?sura=$1 [L]

they must be in this order, in case there is only 1 param, the second rule will be 'executed'. also you may want to limit the type of characters that params can take.

Jump to Post

All 5 Replies

thanks pixelsoul

RewriteEngine On
RewriteRule ^([^/]*)$ /?sura=$1 [L]
RewriteRule ^([^/]*)/$ /?sura=$1 [L]
RewriteRule ^([^/]*)/([^/]*)$ /?sura=$1&ayat=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/$ /?sura=$1&ayat=$2 [L]

This is not working

but only this works

    RewriteRule ^([^/]*)/([^/]*)$ /?sura=$1&ayat=$2 [L]
    RewriteRule ^([^/]*)/([^/]*)/$ /?sura=$1&ayat=$2 [L]

try this:

RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)$ /?sura=$1&ayat=$2 [L]
RewriteRule ^([a-zA-Z0-9-]+)$ /?sura=$1 [L]

they must be in this order, in case there is only 1 param, the second rule will be 'executed'. also you may want to limit the type of characters that params can take.

commented: thanks +2

can you be more specific and give a real example?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.