Changing site URLs in Joomla with Apache mod rewrite - apache

So I'm trying to clean up the URLs on my site, and have digged around for information here and not figured out why I'm still getting errors.
Basically, I have a site that revolves around a search engine, and once the user sees the results and clicks on one, it goes to a URL that looks like:
www.mysearch.com/searchresults/204982398sjfdkf&thisismorejunk=junkjunk=1331
Well, sort of, but you get the point.
I want to clean this up for each result, so it looks like
www.mysearch.com/searchresult1001
I'm using the Joomla platform on my backend, and enabled 'Search Friendly URLs' and there was no problem (although it did almost nothing for me). Then before I enabled 'Use APACHE mod rewrite' I put the following code into my .htaccess file
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^Joomla161_2/joomla\.html http://www.joomla.org/? [R=301,L]
(The last rule was just to see if the rewrite rule works, which it does)
First problem - My host automatically overrides the Options command, saying I can't do it for security reasons - but I figure maybe this isn't big because the rewrite rule still works.
But then when I try to enable 'Use Apache rewrite' my whole site breaks. Worse yet, I have no idea what to do next to actually CHANGE the URLs of my search results.

Options +FollowSymLinks
It is very possible that your host has this enabled by default and
adding to your .htaccess file is causing a conflict.
If your mod-rewrites are working without it then there is no reason
to add it.
Joomla Apache Rewrite
Change the seo settings and htaccess back to default setting.
BEFORE! you change any of the options in the Joomla admin for seo friendly url's or Apache rewrite you must FIRST! rename your htaccess.txt to .htaccess
In some cases you may have to give the server a min or two to notice it.
Now change the Joomla admin settings to seo friendly and enable rewrite.
Search Rewrite
If the above setting are configured correctly then your websites search results will have landing pages with nice urls.

Related

mod_rewrite - Does Apache caches .htaccess rules? (still follow rules even after deleting the .htaccess file)

I was doing some tests with mod_rewrite in my wamp environment.
I tested a simple rule that I put at the root of one of my websites and asked it to redirect any request ending with index.php to localhost (there is no sense to it, just wanted to check the rule)
It worked, but after, any change I'd made to my .htaccess file rule was not reflected.
After a while I just decided to delete the .htaccess... well it's still doing redirection! I just don't understand it. Does Apache cache the rules or something (restarting services trough wamp menu didn't change anything)
(Don't ask for the exact rule I used, since I deleted the file, I don't think it's relevant anyway)
.htaccess files are processed each time a request comes through. It is possible that your browser cached the request being forwarded. Did you try it with httpfox or anything to see what the headers said?
Have you tried deleting the browser cache?

Add on domain mod rewrite to create pretty url

I have a main website www.site.co.uk and one of my add on domains is addon.co.uk. Site has an htaccess as does addon. The folder of which from the root would be www.site.co.uk/addon.co.uk/.htaccess ..I think!
Anyway currently I can do redirects within addon htaccess file fine, but its a database driven site and im trying to create pretty urls for it, so:
http://www.addon.co.uk/addonsites/some.php?id=page
would become:
http://www.addon.co.uk/id/page/
The mod I have in the addon htaccess file is the following:
RewriteEngine On
RewriteRule ^id/([^/]*)/$ /addonsites/some.php?id=$1 [L]
But this has no effect.
Well, the mod_rewrite module will perform translations on requests to the server, so when anyone requests the resource located at http://www.addon.co.uk/id/page/ the server will know that http://www.addon.co.uk/addonsites/some.php?id=page is the place to go.
However, mod_rewrite does in no way modify your existing links. I.e., you should rewrite the HTML (or scripts generating the HTML) to match the "new" way of linking. E.g., if you have ... somewhere on your site, you must make sure it is changed to ....
tl;dr
mod_rewrite handles incoming requests; it does not modify your output (HTML).

Drupal Clean Urls break randomly for arbitrary paths

I've done everything right. My server has mod_rewrite enabled, my virtualhost path has AllowOverride set to All, and I have the .htaccess file in place with the rewrite rules same as everyone. But I have trouble accessing some pages using their clean url paths. So for 90% of the pages, clean urls work fine. But for that 10%, they don't.
I have checked whether those pages exist -- they do. Checked whether they are accessible using index.php?q=[path] -- and they are. They are only inaccessible through clean url paths.
Can anyone help me with this mystery?
Because you can access your pages through q=path/to/menu/item, then it's clear that it is mod_rewrite that is at fault and not Drupal.
To debug what is going on with your rewrite, either turn on the rewrite log and tail -f it while you request the troubled pages, or alternatively print_r($_GET) at the top of index.php or page.tpl.php to see what is actually being requested.
If you are comfortable posting your potentially sensitive .htaccess here, do so and we can have a look at it for you to see if there are any misconfigurations.
mod_rewrite has a few long-standing bugs that mangle URLs on the way through (do your problem urls have any escape characters?). I don't know if Drupal does this, but in other PHP apps I have had to add code to re-do the rewrite once the correct entrypoint has been reached.
Unfortunately, Drupal can't take its search path in PATH_INFO (as a lot of other apps do), otherwise you could use mod_alias which is much simpler and much more reliable.

Problem in apache2 with mod rewrite when setting rules in .conf files instead of .htaccess

Because of weird security policies of my hosting provider I have to define my rewrite rules in /etc/apache2/conf.d/examplesite.conf instead of writing them on an .htaccess on the www folder of that site.
What I'm trying to do is setup a Wordpress Mu server (http://mu.wordpress.org/forums/topic/17349 ) and so far its working on a 50%.
The main blog loads perfectly but other sub blogs (located for example at www.example.com/blog2 ) don't.
I'm guessing the problem is that the rewrite rules behave differently when declared at .conf files for each virtual host instead of using .htaccess files.
Has anybody else had this problem? How can you fix it?
This doesn't sound like a rewrite problem to me but maybe it is. You don't say what the error is when you try to load one of the sub blogs. Perhaps posting up what your rewrite rule is would be helpful. Also would you be able to set up a scenario where you did them in .htaccess files on a localhost or something and seeing if there was a difference?
If pretty permalinks work, then mod_rewrite is enabled, and rewriting URLs to WordPress successfully.
If this is the case, then it's a problem with your MU install.
Did you choose paths over sub-domains during the MU install? If you didn't, but then later switched, that's where the problem is - are you in a position to fresh install?

Redirecting a Directory to a Script on Apache

So I'm playing with a script that makes it super easy to mirror images off of the web. The script works great (based off of the old imgred.com source, if you've seen that) problem is, it looks a little clunky when using it.
Currently, in order to use the script, you go to a url like:
http://mydomain.com/mirror/imgred.php?Image=http://otherdomain.com/image.jpg
What I'd like to do is to be able to go to:
http://mydomain.com/mirror/http://otherdomain.com/image.jpg
and have it redirect to the former URL, preferably transparent to the user.
I'm reasonably certain that this can be done via .htaccess with a MOD_REWRITE of some kind, but I'm getting frustrated trying to get that to work.
After messing with this myself, I found out that apache collapses any double slash in the URL before the query part into a single slash, and passes the result to mod_rewrite. Maybe that was giving you problems?
This might work for you (.htaccess in the mirror directory):
RewriteEngine On
RewriteBase /mirror
RewriteRule ^http(s?):/(.*) imgred.php?Image=http$1://$2 [L]
Don't know if your script accepts https addresses as well, so I included that just to be sure