Link to home
Start Free TrialLog in
Avatar of j-b-t
j-b-tFlag for Australia

asked on

Help with redirect in htaccess for long php url

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
Avatar of ravenpl
ravenpl
Flag of Poland image

Well, this code works.
Yet it fires only for http://mywebsite.com/123456
Also, You don't need the "" enclosure, nor \ escaping.
Avatar of j-b-t

ASKER

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
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.
Avatar of j-b-t

ASKER

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)

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??
Avatar of j-b-t

ASKER

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]

ASKER CERTIFIED SOLUTION
Avatar of ravenpl
ravenpl
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of j-b-t

ASKER

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
Avatar of j-b-t

ASKER

Didn't solve problem - but certainly gave me enough info to work through it and find an alternative soln - thanks for your patience!