logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Help getting redirects that use /index.php to work
Author
JohnM



Joined: 27 Jun 2013
Posts: 4

PostPosted: Thu 27 Jun '13 20:36    Post subject: Help getting redirects that use /index.php to work Reply with quote

I am rebuilding my Joomla website and am having trouble getting some redirects to work. I'm using the following versions:
Apache 2.2.24
PHP 5.4.16
MySQL 5.5.32
Joomla 3.1

I've been able to use the Joomla redirect module to get non-index.php links to work. However I can't get redirects that use index.php to work. For example, I can't redirect the following:

OLD URL
http://www."MYDOMAIN".net/index.php?option=com_mad4joomla&jid=3&Itemid=64

I get a 404 page for this URL.

I've tried the following in my .htaccess file with no luck:

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
redirect 301 /index.php?option=com_mad4joomla&jid=3&Itemid=64 http://www."MYDOMAIN".com/john/NEW
## End - Custom redirects

I've been searching through Apache redirect/rewrite and PHP documentation but I'm in over my head.

Can anyone help me get these redirects working properly? Thank you!
Back to top
black_harry



Joined: 22 Feb 2010
Posts: 15
Location: Germany, Stuttgart

PostPosted: Fri 28 Jun '13 9:28    Post subject: Reply with quote

If you want to redirect all requests to index.php, I would suggest to use RedirectMatch with a regular expression:

if you want to have it case insensitive (helpful for apache on windows), this one should work (it checks if the path starts with /index.php):
RedirectMatch 301 ^/(?i:index\.php) http://www."MYDOMAIN".com/john/NEW

If you want to have it case sensitive:
RedirectMatch 301 ^/index\.php http://www."MYDOMAIN".com/john/NEW

If you need the complete url, you only have to escape the special characters in your url (.?&):
RedirectMatch 301 ^/index\.php\?option=com_mad4joomla\&jid=3\&Itemid=64$ http://www."MYDOMAIN".com/john/NEW

... hope this helps.
Back to top
JohnM



Joined: 27 Jun 2013
Posts: 4

PostPosted: Sun 30 Jun '13 19:35    Post subject: Reply with quote

Thanks for your help. Unfortunately these didn't work.

When I use
RedirectMatch 301 ^/(?i:index\.php) http://www."MYDOMAIN".com/john/NEW

... I get the following:

The page isn't redirecting properly. Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

When I use
RedirectMatch 301 ^/index\.php\?option=com_mad4joomla\&jid=3\&Itemid=64$ http://www."MYDOMAIN".com/john/NEW

... I get the same 404.

Surely there must be someway I can control how index.php handles redirects?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Mon 01 Jul '13 16:06    Post subject: Reply with quote

I would try something like

RewriteEngine On
RewriteRule RewriteRule ^(index\.php) http://www."MYDOMAIN".com/john/NEW%{REQUEST_URI} [L]
Back to top
JohnM



Joined: 27 Jun 2013
Posts: 4

PostPosted: Mon 01 Jul '13 18:57    Post subject: Reply with quote

Did you mean to write 'RewriteRule' twice? I tried it both ways. With RewriteRule twice I get an internal server error. With RewriteRule once I get a blank page.

The [L] is embedded in the address window. It's directly after /NEW.

Also, you have {REQUEST_URI}. Did you mean to write {REQUEST_URL}?

Still no luck, but I appreciate the help.
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7373
Location: Germany, Next to Hamburg

PostPosted: Tue 02 Jul '13 16:43    Post subject: Reply with quote

Sorry for the mess. Too much copy and paste...
this it should only to be.

Code:

RewriteEngine On
RewriteRule ^(index\.php) http://www."MYDOMAIN".com/john/NEW%{REQUEST_URI}



However the issue with the 301 is that is always matches and forces the browser into a loop. May you could put that into <Location "/"></LOcation>
Back to top
JohnM



Joined: 27 Jun 2013
Posts: 4

PostPosted: Wed 03 Jul '13 3:06    Post subject: Reply with quote

No luck with this either. Depending on where I put this rule in the .htacess I either get a 404 or blank page. It IS rewriting the URL but I still get this in the URL:

?option=com_mad4joomla\&jid=3\&Itemid=64$

I'm not currently using the lines the have 301's in them.

Perhaps you would be willing to look at my .htaccess? I'd be most grateful.
Back to top
black_harry



Joined: 22 Feb 2010
Posts: 15
Location: Germany, Stuttgart

PostPosted: Thu 04 Jul '13 17:08    Post subject: Reply with quote

I have a question:
do you need the Request-URI at the redirected page?

I did a test:
RedirectMatch 301 ^/(?i:index.php).*$ http://my_server/cgi-bin/printenv.pl
redirects the page, but adds the Request-URI to the target-link. So I got a redirect to
http://my_server/cgi-bin/printenv.pl?option=com_mad4joomla&jid=3&Itemid=64

If you do not want to keep the Request-URI, a 301 is not the complete solution.
I do not know if rewrite can do the job, but if you are willing to use an AliasMatch at the target server, you could cut off the parameters there - I hope the regex is the correct one:
AliasMatch ^/john/NEW\?option=com_mad4joomla\&jid=3\&Itemid=64$ Drive:/Path/file
If the escaped characters do not work, a .+ (that means 1..n characters) will help:
AliasMatch ^/john/NEW.+option=com_mad4joomla.+jid=3.+Itemid=64$ Drive:/Path/file
Back to top


Reply to topic   Topic: Help getting redirects that use /index.php to work View previous topic :: View next topic
Post new topic   Forum Index -> Apache