Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help with redirect in htaccess for long php url

Posted on 2009-07-04
9
Medium Priority
?
580 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
[X]
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
  • 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
Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

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

Question has a verified solution.

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

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

722 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