Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Apache Rewrite Rule And Redirects?

apache httpd.conf .htaccess rewriteRule mod_rewrite redirect

  • Please log in to reply
4 replies to this topic

#1 Stasonix

Stasonix

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 115 posts
  • Programming Language:C++, PHP, JavaScript, Delphi/Object Pascal, Pascal
  • Learning:C++, PHP, JavaScript, Delphi/Object Pascal

Posted 24 June 2012 - 07:16 PM

Hope I choosed right forum branch. So I want to configure .htaccess for this situation - I have some page http://mysite/category/page, and I want to remove "category" from this url, will be like that http://mysite.com/page, how to write a rewrite rule for this?
  • 0

#2 denvit

denvit

    CC Lurker

  • New Member
  • Pip
  • 4 posts
  • Location:Slovenia
  • Programming Language:C#, PHP, JavaScript

Posted 25 June 2012 - 01:19 AM

I'm not sure if this will working, but give it a try :)

RewriteEngine  on
RewriteRule ^category/(.+)$ http://www.yourblog.com/$1 [R=301,L]

  • 0

#3 Stasonix

Stasonix

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 115 posts
  • Programming Language:C++, PHP, JavaScript, Delphi/Object Pascal, Pascal
  • Learning:C++, PHP, JavaScript, Delphi/Object Pascal

Posted 25 June 2012 - 03:33 AM

No, it's will not work if the user type http://mysite.com/page. Tested it before. I think it's impossible.
  • 0

#4 niko619

niko619

    CC Newcomer

  • Member
  • PipPip
  • 14 posts

Posted 03 July 2012 - 05:13 PM

see if this works

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^((?!changeme/).*)$ changeme/$1 [NC,L]

replace changeme with the directory name. let me know if it works
  • 0

#5 Stasonix

Stasonix

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 115 posts
  • Programming Language:C++, PHP, JavaScript, Delphi/Object Pascal, Pascal
  • Learning:C++, PHP, JavaScript, Delphi/Object Pascal

Posted 07 July 2012 - 09:52 AM

Hi again, I feel confused with rewriterules, I did archive with example what I am want to do - http://rghost.ru/39091349, hope it's will be easier to understand me.

So there is two rules, 1 is good if the link looks like http://test.loc/php/array and rule is : RewriteRule ^([^/]*)/([^/]*)$ index.php?cat=$1&article=$2 [L,QSA]

and the other is not what I am expected: http://test.loc/php [ rule] : #RewriteRule ^([^/]*)$ index.php?cat=$1 [L,QSA]

I have commented it 'caz it's almost work, but not as I want, if I go http://test.loc it will always show me "we get only name of the article, we did query to db and show only name of articles", but I need a content of the main page.
  • 0





Also tagged with one or more of these keywords: apache, httpd.conf, .htaccess, rewriteRule, mod_rewrite, redirect

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download