Solved

Help with redirect in htaccess for long php url

Posted on 2009-07-04
9
567 Views
Last Modified: 2012-05-07
Hmm using joomla - mod rewrite is on - why doesn't this work? Code from .htaccess

Redirect 301 /index.php?option=com_content&view=article&id=7&Itemid=0 http://mywebsite.com/component/jevents/icalrepeat.detail/2009/07/20/4/2/YjVhOWExYWNjNjI5ZmNlZDIzNzEzMWIzNDU2ZmU3NWE=

RewriteCond %{HTTP_HOST} ^mywebsite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mywebsite.com$
RewriteRule ^123456$ "http\:\/\/mywebsite\.com\/component\/jevents\/icalrepeat\.detail\/2009\/07\/20\/4\/2\/YjVhOWExYWNjNjI5ZmNlZDIzNzEzMWIzNDU2ZmU3NWE\=" [R=301,L]


Thanks
0
Comment
Question by:j-b-t
  • 5
  • 4
9 Comments
 
LVL 43

Expert Comment

by:ravenpl
ID: 24777072
Well, this code works.
Yet it fires only for http://mywebsite.com/123456
Also, You don't need the "" enclosure, nor \ escaping.
0
 
LVL 11

Author Comment

by:j-b-t
ID: 24778570
Thanks ravenpl - I had a small error in that code..... the code I am trying to get working is:

Redirect 301 /index.php?option=com_content&view=article&id=7&Itemid=0 http://mydomain.com/component/jevents/icalrepeat.detail/2009/07/20/4/2/YjVhOWExYWNjNjI5ZmNlZDIzNzEzMWIzNDU2ZmU3NWE=


RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^index\.php$ "http\:\/\/mydomain\.com\/component\/jevents\/icalrepeat\.detail\/2009\/07\/20\/7\/2\/YjVhOWExYWNjNjI5ZmNlZDIzNzEzMWIzNDU2ZmU3NWE\=" [R=301,L]

I'm sure I've read somwhere there is a problem with the php? (maybe just the questionmark) so I tried:
RewriteRule ^index\.php\?$ "  etc etc - but didn't help
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 24778894
You still haven't said what You entering in the urlbar, and what You expecting.

Still, redirect will not work with query string, so all You can is

Redirect 301 /index.php http://mydomain.com/component/jevents/icalrepeat.detail/2009/07/20/4/2/YjVhOWExYWNjNjI5ZmNlZDIzNzEzMWIzNDU2ZmU3NWE=

For rewrite, You have to match the query string on rewriteCond like

RewriteCond %{QUERY_STRING} ^docid=([0-9]+)
RewriteRule (.*) $1/%1

Now, please tell me what You're expecting from the code, then I'll try to help You with that.
0
 
LVL 11

Author Comment

by:j-b-t
ID: 24778905
Thanks Raven - I obviously have no idea. My apologies

I want to redirect the page called
http://www.mydomain.com/index.php?option=com_content&view=article&id=7&Itemid=0
to
http://www.mydomain.com/component/jevents/icalrepeat.detail/2009/07/20/4/2/YjVhOWExYWNjNjI5ZmNlZDIzNzEzMWIzNDU2ZmU3NWE=
( So when you click on a link to the first url you essentilly end up at eth second)
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 43

Expert Comment

by:ravenpl
ID: 24778917

RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteCond %{QUERY_STRING} ^option=com_content&view=article&id=7&Itemid=0
RewriteRule index.php /component/jevents/icalrepeat.detail/2009/07/20/4/2/YjVhOWExYWNjNjI5ZmNlZDIzNzEzMWIzNDU2ZmU3NWE= [L,R=301]

Strip the R=301 from flags, if You want to hide the redirection from user.
Redirects are usually used for bulk matched redirects, though I cannot find any dependencies between original and redirected urls??
0
 
LVL 11

Author Comment

by:j-b-t
ID: 24778954
Thanks - I must be doing something wrong still

Here is my entire .htaccess file -  amybe something else is interfering.. ?

when I add your code with corrected domain - i'm not getting a redirect - just goes to the original page/article - your're right I don't need the 301(PS - Ive checked that mod_rewrite is on in joomla and tried a few variations of the code - but I'm just guessing really

#####################################################
#  READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations.  It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file.  If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's.  If they work,
# it has been set by your server administrator and you do not need it set here.
#
#####################################################

##  Can be commented out if causes errors, see notes above.
Options +FollowSymLinks

#
#  mod_rewrite in use

RewriteEngine On

########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits

#  Uncomment following line if your webserver's URL
#  is not directly related to physical file paths.
#  Update Your Joomla! Directory (just / for root)

# RewriteBase /

########## Begin - Joomla! core SEF Section
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

#
########## End - Joomla! core SEF Section


RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
RewriteCond %{QUERY_STRING} ^option=com_content&view=article&id=7&Itemid=0
RewriteRule index.php/component/jevents/icalrepeat.detail/2009/07/20/4/2/YjVhOWExYWNjNjI5ZmNlZDIzNzEzMWIzNDU2ZmU3NWE= [L,R=301]

0
 
LVL 43

Accepted Solution

by:
ravenpl earned 500 total points
ID: 24778962
> RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$
Have You changed it to Your actual domain? If You have multiple, please comment it out.

> RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
Try stripping the L flag - it causes rewrite engine to terminate processing - and the .* matches anything.
0
 
LVL 11

Author Comment

by:j-b-t
ID: 24779002
Thanks  - I really can't get this working - I really can't seem to work out why.

I've found a module that seems to have a work around momentarilly (http://extensions.joomla.org/extensions/structure-&-navigation/url-redirection/7189/details) ... but I'm still struggling a bit with it.

But many thanks
0
 
LVL 11

Author Closing Comment

by:j-b-t
ID: 31599738
Didn't solve problem - but certainly gave me enough info to work through it and find an alternative soln - thanks for your patience!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

18 Experts available now in Live!

Get 1:1 Help Now