Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

.htaccess - help needed with RewriteRule

Posted on 2012-03-19
6
Medium Priority
?
396 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
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.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

916 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