Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

.htaccess - help needed with RewriteRule

Posted on 2012-03-19
6
363 Views
Last Modified: 2012-06-21
Hi,
I have some rewrite rules which cause links such as <a href="Coaches">Coaches</a> to redirect to a specific page which works fine, but if I have a link to a file that contains the same name then it will also redirect.

http://www.mywebsite.com/uploads/web_pages/3CD%20R%20and%20R%20Coaches.pdf

How should "RewriteRule Coaches index.php?page_id=262" be written to work for the first link but not the other?

Thanks in advance for your feedback.


Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mywebsite.com$ [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]
RewriteRule ([0-9]+)(.*)\.html$ index.php?page_id=$1


RewriteRule Home\ Page index.php?page_id=1
RewriteRule Club\ Details index.php?page_id=14
RewriteRule Coaches index.php?page_id=262
0
Comment
Question by:sabecs
  • 3
  • 3
6 Comments
 
LVL 11

Expert Comment

by:Amar Bardoliwala
ID: 37737371
Hello sabecs,

you should use following

RewriteRule ^Coaches(.*)  index.php?page_id=262

Hope this will help you.

Thank You.

Amar Bardoliwala
0
 

Author Comment

by:sabecs
ID: 37737570
Thanks Amar for your help, I tried your suggestion but its not redirecting?
0
 
LVL 11

Expert Comment

by:Amar Bardoliwala
ID: 37737687
Hello sabecs,

you are trying to say that your page is redirecting to index.php?page_id=262 for following

http://www.mywebsite.com/uploads/web_pages/3CD%20R%20and%20R%20Coaches.pdf

right?

Please try following

RewriteRule ^Coaches$ index.php?page_id=262

Also I think you should have following in your .htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R]

Hope this will help you.

Thank You.

Amar Bardoliwala
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:sabecs
ID: 37738208
Thanks again for your help, this is what i have in my .htaccess file,

SetEnv PHPRC /home/mywebsit/public_html
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^www.mywebsite.com$ [NC]
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]
RewriteRule ([0-9]+)(.*)\.html$ index.php?page_id=$1

RewriteRule Home\ Page index.php?page_id=1
RewriteRule Club\ Details index.php?page_id=14
RewriteRule About\ Us index.php?page_id=254
RewriteRule History index.php?page_id=256
RewriteRule Roles\ &\ Responsibilities index.php?page_id=257
RewriteRule Committee\ Descriptions index.php?page_id=258
RewriteRule Comps\ and\ Programs index.php?page_id=248
RewriteRule Policies\ and\ Guidelines index.php?page_id=259
RewriteRule Awards index.php?page_id=260
RewriteRule Insurance index.php?page_id=261
RewriteRule ^Coaches$ index.php?page_id=262
RewriteRule Players index.php?page_id=263
RewriteRule Team\ Managers index.php?page_id=264
RewriteRule Parents index.php?page_id=265
RewriteRule Contacts index.php?page_id=266
RewriteRule Store index.php?page_id=274
RewriteRule Price\ List index.php?page_id=276
RewriteRule Information index.php?page_id=229
RewriteRule Subscription\ Form index.php?page_id=235

Yes, previously  http://www.mywebsite.com/uploads/web_pages/3CD%20R%20and%20R%20Coaches.pdf was redirecting to index.php?page_id=262 which I don't want, so that has been fixed but now <a href="Coaches">Coaches</a> won't redirect either?
0
 
LVL 11

Accepted Solution

by:
Amar Bardoliwala earned 500 total points
ID: 37738375
Hello sabecs,

Please backup of your old .htaccess file and see if following works as per your expectations

SetEnv PHPRC /home/mywebsit/public_html
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mywebsite.com$ [NC]
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule .* - [L]
RewriteRule \.(css|jpe?g|gif|png|pdf|js|jpg|ico)$ - [L]

RewriteRule Home\ Page index.php?page_id=1
RewriteRule Club\ Details index.php?page_id=14
RewriteRule About\ Us index.php?page_id=254
RewriteRule History index.php?page_id=256
RewriteRule Roles\ &\ Responsibilities index.php?page_id=257
RewriteRule Committee\ Descriptions index.php?page_id=258
RewriteRule Comps\ and\ Programs index.php?page_id=248
RewriteRule Policies\ and\ Guidelines index.php?page_id=259
RewriteRule Awards index.php?page_id=260
RewriteRule Insurance index.php?page_id=261
RewriteRule Coaches index.php?page_id=262
RewriteRule Players index.php?page_id=263
RewriteRule Team\ Managers index.php?page_id=264
RewriteRule Parents index.php?page_id=265
RewriteRule Contacts index.php?page_id=266
RewriteRule Store index.php?page_id=274
RewriteRule Price\ List index.php?page_id=276
RewriteRule Information index.php?page_id=229
RewriteRule Subscription\ Form index.php?page_id=235

RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [L,R=301]
RewriteRule ([0-9]+)(.*)\.html$ index.php?page_id=$1


Hope this will help you.

Thank You.

Amar Bardoliwala
0
 

Author Closing Comment

by:sabecs
ID: 37769516
Thanks Amar for your help, much appreciated. Sorry for late response..
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question