[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

htaccess redirect

I need to set up an htaccess file that will redirect from http://domainname.com/dirname/  to http://domainname.com/dirname?section=way&gallery=About&sample=1 and maintain the url http://domainname.com/dirname/ in the address bar. I've tried the code below, but it does not do the forwarding. Can someone please let me know how this should be done?

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domainname.com/dirname/$ [OR]
RewriteCond %{HTTP_HOST} ^www.domainname.com/dirname/$
RewriteRule ^(.*)$ /domainname.com/dirname//index.php?section=way&gallery=About&sample=1 [R=301,L]
0
jzilberberg
Asked:
jzilberberg
  • 3
1 Solution
 
Brad HoweCommented:
Are you looking to MASK the URL or simply redirect?

Rewrite rules don't actually hide the query string. They pretty much convert seo friendly urls domain.com/PATH into the actual domain url + query string

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domainname.com/dirname/$ [OR]
RewriteCond %{HTTP_HOST} ^www.domainname.com/dirname/$
RewriteRule ^(.*)$ index.php?section=way&gallery=About&sample=1 [R=301,L,NC]

The mask the URL would you need to use a iframe or a post page to hide the parameters.

Best Regards,
-Hades666
0
 
jzilberbergAuthor Commented:
Ok, thank you. I guess the iframe solution will work for now if there is not a way to mask the url parameters via htaccess.
0
 
Brad HoweCommented:
Hi,

Sorry misunderstood this completely and don't know what i was thinking. You should be able to do it like such with mod_rewrite using an internal redirect.

RewriteEngine on
RewriteLog /somefolder/rewrite.log
RewriteLogLevel 9
RewriteRule ^/(.*)/?$ /$1/index.php?section=way&gallery=About&sample=1 [PT,NC,QSA,L]


PT = Forces the resulting URI to be passed back to the URL mapping engine for processing of other URI-to-filename translators, such as Alias or Redirect

Essentially, a user will request http://domain.com/test/ or domain.com/test and get /test/index.php?section......

browser will still show /test/ but the content in the page will be from index.php.

Sorry about that, Give this a shot,
Hades666
0
 
Brad HoweCommented:
The logging portion should also be added to the httpd.conf only IF you are having rewrite issues and want to debug.

Cheers,
Hades666
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now