• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

htaccess for redirection and query strings

Hi there,
I'm trying to use htaccess, but I'm having problems trying to accomplish 3 tasks simultaneously.

1. Redirect http://www.mydomain.com to http://mydomain.com

2. Use clean URLs so that
http://mydomain.com/samplepage
points at
http://mydomain.com/page.php?htmlID=samplepage 

3. Add exception(s) so that
http://mydomain.com/admin
DOES NOT point at
http://mydomain.com/page.php?htmlID=admin

I appreciate your help. Thanks
0
skylabel
Asked:
skylabel
  • 2
2 Solutions
 
pritamduttCommented:
You have specified the requirements, but have failed to mention the issues faced by you.

Kindly let us know the challenges being faced.

Regards,
0
 
skylabelAuthor Commented:
I've got tthe following, but I can't get that exception thing working for
http://mydomain.com/admin

# AddType application/x-httpd-php .html .php .htm
AddType php5-cgi htm html
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com [NC]
 RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www.)?mydomain\.com$ [NC]
RewriteRule ^(.+)/$ http://mydomain.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^/admin/
RewriteRule ^([a-zA-Z0-9_-]+)$ page.php?htmlID=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ page.php?htmlID=$1

Open in new window

0
 
xtermCommented:
I think your easiest course would be simply to split into two vhosts in your httpd.conf (they can have the same root, it doesn't really matter, but this way you can apply your rewrite rules to each with simplicity).  This should actually do everything you need.


#In VirtualHost for mydomain.com:
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/admin/
    RewriteRule ^/samplepage            http://mydomain.com/page.php?htmlID=samplepage [L,R]

#In VirtualHost for www.mydomain.com:
    RewriteEngine On
    # This will redirect www.mydomain.com to mydomain.com
    # It will preserve args too, so www.mydomain.com/foo goes to mydomain.com/foo
    RewriteRule ^/(.*)                  http://mydomain.com/$1 [L,R]

Open in new window

0
 
pritamduttCommented:
Hi...

Please make change the lines 9-11 as below and test. This works fine for me.

RewriteCond %{REQUEST_URI} !^/?admin//* [NC]
RewriteRule ^([a-zA-Z0-9_-]+)/?$ page.php?htmlID=$1
#RewriteRule ^([a-zA-Z0-9_-]+)/$ page.php?htmlID=$1

Open in new window



Regards,
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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