0

I want to use url rewriting in my site as follow: When user try to access

http://www.mysite.com/sectionname/

for processing it must go to file as

http://www.mysite.com/handler.php?sect=sectionname

but in address bar user must see first url only.

I used following code but it's not working

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^/]+)$ sectionthumbs.php?sect=$1

but it's not working. Please tell me where I m wrong. Thanks in advance....

2 Answers 2

2

Something like this should work:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /handler.php?sect=$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

Comments

0

As @Repox said,

however I use something like this for all my past projects:

RewriteRule ^([^/\.]+)/$ index.php?module=$1 [L]

But that's because I use MVC

Another little trick, say that you had a variable passed into the query string, to make it look pretty /media/this_is_article you would use something like:

RewriteRule ^media/([^/\.]+)/?$ index.php?media=$1 [L]

2 Comments

Using a MVC framwork like CodeIgniter allow you to use my suggestion as well with the difference that the request would be pointed to index.php/$1 instead. The framework then finds out which controller (module if you will), wich controller method and if needed, passes any arguments to the method as well. By applying your suggestion the rewrite seems less flexible.
Yes I use codeignitor myself; but as codeignitor and most MVC frameworks do this this automatically I presumed the original question was him wanting to do it by himself by developing his own 'framework' if you will, that's why I provided this. Cheers.

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.