Solved

.htaccess - help needed with RewriteRule

Posted on 2012-03-19
6
332 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

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.

Join & Write a Comment

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now