homepage Welcome to WebmasterWorld Guest from 50.17.7.84
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Content Management
Forum Library, Charter, Moderators: ergophobe

Content Management Forum

    
Joomla .htaccess rewrite
.htaccess, joomla, url-rewriting, rewrite
RobbyBubble




msg:4556131
 5:12 pm on Mar 18, 2013 (gmt 0)

Just trying to change my URL from
http://example.com/index.php/streams/shinigamily to http://example.com/shinigamily

I activated the Rewrite Option in the admin panel and used the original joomla htaccess file and the url went to
http://example.com/streams/shinigamily

At this point I wrote RewriteRule ^streams/(.*)/?$ /$1 [L,NC,R] after the
# RewriteBase /

Somehow it doesnt work. My webhost already edited his httpd.conf with

<Directory "/home/htdocs/webX/html">
AllowOverride All
Options +FollowSymLinks +SymLinksIfOwnerMatch
</Directory>


But it didnt change anything either.

Now, the hard way is much more advanced and requires you to do the following:

Modify Joomla�s SEF core files in order to remove the category name from the URL. (Note: There are several files that need to be changed.)

Ensure that the change you�ve done above is accommodated in your .htaccess file.

Ensure that you don�t break any functionality with this code change.


Blackquote of
http://www.itoctopus.com/how-to-remove-the-category-name-from-the-url-in-joomla

Now I feel sunk.

Here is my htacces file:

##
# @packageJoomla
# @copyrightCopyright (C) 2005 - 2013 Open Source Matters. All rights reserved.
# @licenseGNU General Public License version 2 or later; see LICENSE.txt
##

##
# 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 base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%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})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.

## 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.
#
## End - Custom redirects

##
# 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.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
RewriteRule ^streams/(.*)/?$ /$1 [L,NC,R]
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.

[edited by: ergophobe at 6:29 pm (utc) on Mar 18, 2013]
[edit reason] No URLs that would lead to your site thanks (see site usage terms) [/edit]

 

lucy24




msg:4556213
 9:33 pm on Mar 18, 2013 (gmt 0)

Urk. Too much information :)

Just trying to change my URL from

This question should really have been posted in the Apache forum. But it's just as well it wasn't, because g1smd-- who has forgotten more about joomla and htaccess than the rest of us ever knew in the first place-- would then have read you the riot act about "making" or "changing" URLs.

There are two processes, and you need to be clear on which is which and where they happen.

One process is the redirect. That's the part where the user-- you, f'rinstance-- types in an URL and when they look at their browser's address bar it says something other than what they typed.

The other process is the rewrite. That's the part where your server receives a request for /directory/filename and instead serves up a page that lives at /otherdirectory/otherfilename. (Or that doesn't live anywhere, if you're dealing with php.)

When you're working with a CMS that came with a ready-made htaccess, it is crucial to get your rules in the right places so they don't overwrite/ supersede/ contradict the existing rules. Redirects come before rewrites; that's about the only safe generalization.

Still with us?

Your next step is to forget everything I just said, and backtrack. Explain in English, in ordinary human terms,

#1 what your user is likely to type in
#2 what you want your user's address bar to say
#3 where the content really lives

RobbyBubble




msg:4556222
 9:51 pm on Mar 18, 2013 (gmt 0)

Honestly my website worked fine before I even used a htaccess file. The only reason why I converted the already existing htaccess.txt to .htaccess was to make the link shorter.
A tutorial gave me the information the original joomla htaccess will hide the /index.php/ in any links.
The link is too large to share it on the game the website is focused on.

Then I used RewriteRule
^streams/(.*)/?$ /$1 [L,NC,R] to get rid of the category.

Sadly Im not able to write a htaccess file by my own.

So the link shoudlt work by using the menu and by entering the url into a browser.

Is it now more understandable?

lucy24




msg:4556253
 12:29 am on Mar 19, 2013 (gmt 0)

The only reason why I converted the already existing htaccess.txt to .htaccess was to make the link shorter.

Say what now?

htaccess.txt is one possible name for the non-functioning copy of your htaccess file-- the one you use when you need to edit its content. You have-- or should have-- this file on your personal hard drive along with everything else pertaining to the site.

.htaccess --with leading dot and no extension --is the working file. This is the only name it can have, and if it's in the appropriate location it will work whether you ask it to or not. Unless your host doesn't allow htaccess files at all and has configured the server accordingly.

Is it now more understandable?

Not entirely, but let me explain what your existing rule does.

RewriteRule ^streams/(.*)/?$ /$1 [L,NC,R]

#1 Since there is no preceding RewriteCond looking at {THE_REQUEST} and no [NS] flag, this rule will work on all requests that pass through the directory the .htaccess lives in. It doesn't matter who first made the request-- the server or the human user's browser.

#2 The rule will work on all requests whose URL starts with a directory /streams/ located directly inside the directory the htaccess file lives in. So if the htaccess is in your root directory-- the usual pattern-- it will work for www.example.com/streams/anything-or-nothing-here. If the htaccess is in a directory called /dir/ it will work for /dir/streams/etcetera. If the htaccess is in the /streams/ directory it will probably not work at all, unless your structure is /streams/streams/ (nested).

#3 It does not matter what, if anything, comes after /streams/ The (.*) means "nothing or something". The /?$ means "there might be a directory slash at the very end". If there is one, it has already been included in the (.*) capture.

#4 The leading / in the target (the part on the right) means that the changed stuff will be attached to whatever the original root was. Requests for www.example.com/streams/something will end up as www.example.com/something-else, while requests for example.com/streams/something will end up as example.com/something-else.

#5 the [L] flag means "OK, we're done with mod_rewrite, on to the next mod". This flag is almost always correct and necessary.

#6 the [NC] flag means the rule will work on /streams/ but also on /STREAMS/ or /Streams/ or any of the other 2^7 - 3 possibilities. This is OK in a redirect, though not really necessary. You are allowed to insist that your users spell your name right.

#7 the [R] flag changes the rule from an internal rewrite to an external 302 (temporary) redirect. That means the browser's address bar changes, but search engines will probably list the page under the earlier URL-- the one with /streams/.

I strongly suspect that some of the foregoing is not what you want. But it's what the rule currently does.

RobbyBubble




msg:4556276
 1:45 am on Mar 19, 2013 (gmt 0)

Thanks for explaining me the used RewriteRule. I just dont get where the point is of explaining a apparently wrong RewriteRule.

g1smd




msg:4556283
 1:54 am on Mar 19, 2013 (gmt 0)

Compare what it does (as detailed above) as a result of how it was coded, compared with what you actually wanted it to do.

RobbyBubble




msg:4556289
 2:08 am on Mar 19, 2013 (gmt 0)

I can see that. Its nice of him that he explained it. Bad thing is it doesn't help me with my problem.
I just need a working code to convert

example.com/index.php/streams/shinigamily
example.com/index.php/streams/cash
example.com/index.php/streams/blacktigrex
example.com/index.php/streams/viktorwwe

to

example.com/shinigamily
example.com/cash
example.com/blacktigrex
example.com/viktorwwe

[edited by: bill at 4:20 am (utc) on Mar 19, 2013]
[edit reason] use example.com [/edit]

lucy24




msg:4556298
 3:29 am on Mar 19, 2013 (gmt 0)

Ouch! Where'd the "index.php" come from? That was never in the rule. And it can't be because the rule lives in a directory called "index.php" ;)

RobbyBubble




msg:4556299
 3:30 am on Mar 19, 2013 (gmt 0)

If you want to help me, tell me what to change in here:

Options +FollowSymLinks

## Mod_rewrite in use.

RewriteEngine On

RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})

RewriteBase /

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^streams/(.*)/?$ /$1 [L,NC,R]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]


Many thanks in advance!

//edit: I'd like to change my domain to example.com but I can't edit it anymore.

RobbyBubble




msg:4556580
 9:05 pm on Mar 19, 2013 (gmt 0)

Just tried
RewriteRule ^streams/(.*)$ http://example.com/$1 [R=301,L]

I apologize for being completely unresourceful. I really need to get it working.

Andy Langton




msg:4556648
 12:00 am on Mar 20, 2013 (gmt 0)

First things first, do your desired URLs currently work?

I.e. if you visit example.com/shinigamily do you see the content you would like to see? If you don't then you need a rewrite (not a redirect). If you do see the right content, then you need a redirect :)

lucy24




msg:4556663
 1:58 am on Mar 20, 2013 (gmt 0)

if you visit example.com/shinigamily do you see the content you would like to see? If you don't then you need a rewrite (not a redirect). If you do see the right content, then you need a redirect

If the URL shows the intended content, then a redirect alone won't help. You need a redirect and a rewrite, so it continues to show the same content. Even outside the CMS realm:

example.com/index.html
...and that's all

vs.

example.com/index.html
redirect to
example.com/
rewrite (done by mod_dir without your help) to show content of
example.com/index.html

... putting you right back where you started, but what a difference.

I apologize for being completely unresourceful.

Hey, if you figured it out yourself, "completely unresourceful" no longer applies :) Cheers. But where'd the "index.php" go?

RobbyBubble




msg:4556668
 2:36 am on Mar 20, 2013 (gmt 0)

@Andy Langton: They currently work, yes. But /streams/ is still there.

I think index.php is removed since I enabled URL Rwrite in the Global Configuration.

Im bogged down.

lucy24




msg:4556686
 4:50 am on Mar 20, 2013 (gmt 0)

I think index.php is removed since I enabled URL Rwrite in the Global Configuration.

This is the part where you have to be very very careful. You have two choices. They're both OK choices, but you have to pick one:

#1 "I don't understand this mod_rewrite stuff and I'm not touching htaccess with a barge pole, so just tell me where to click"
#2 "The out-of-the-box program doesn't do everything I want it to do, so I'll need to edit my htaccess file directly."

Once you've gone with #2 -- which you must have done, or you wouldn't be posting here -- you can no longer say "I clicked a button and that took care of it". You need to know exactly what happens when you click that button. Worst case: the program may have created a new htaccess file, using your current preference settings but overwriting anything that you added earlier on your own.

Have a look at your site's htaccess file. Not the working copy on your hard drive, but the real one that's on the live site. Does it say everything you expected it to say and nothing that you didn't expect?

RobbyBubble




msg:4556757
 11:18 am on Mar 20, 2013 (gmt 0)

Did you finished trolling me? You waste much time telling me what I did obviously wrong. If you had spend your invested time for helping me instead, I would have been gone already.

g1smd




msg:4556758
 11:25 am on Mar 20, 2013 (gmt 0)

This isn't a free "write your code for you" helpdesk. It's expected that you attempt to learn how to code this stuff yourself.

People here will give you hints, and try to point you in the right direction, but it's unlikely someone will write out chunks of code that you just copy and paste into your site without any understanding of how that code works.

Indeed, because every site is different and there's so many possibilities for what you want to do, it is vital that you fully understand every line of code, what it does, how it works, what its limitations are, and how it might badly interact with other code you may already have, or may add in the future.

htaccess does not "make" URLs, nor can it "change" a URL. It cannot alter the links on your pages. The first question is this: is your Joomla site linking to the URLs that you want users to "see" and "use"? That's the first step.

After that link is clicked, htaccess should then begin to do its stuff: rewriting that request to fetch the content from the server filesystem, from the non-default internal location as defined by the rewrite.

The last part is to add a redirect. This is for users clicking links in stale SERPs, old bookmarks, and links from other sites. When they request the old URL, your site redirects them to the new URL. Their browser then makes a new request for the new URL. This part can work only when all the other parts have been put in place.

Your site should link only to the new URLs and that involves altering the PHP scripts (usually with an add-on or extension). That's the first step.

ergophobe




msg:4556835
 2:44 pm on Mar 20, 2013 (gmt 0)

RoryBubble, one issue is that people have trouble helping for the same reason that the computer has trouble helping - we need a very clear statement of the problem before we can even start on a solution.

So the key point is

It cannot alter the links on your pages. The first question is this: is your Joomla site linking to the URLs that you want users to "see" and "use"? That's the first step.


Your reply to Andy_Langton says

They currently work, yes. But /streams/ is still there.


Where is "there"?
- in the address bar URL after the page loads?
- in the HTML code on the page?

It still is not at all clear to me what you're trying to accomplish, but it sounds to me based on your answer that your rewrites are working fine, what's not working fine is Joomla.

So this is how I understand the situation based on your reply to Andy_Langton:

1. These URLs currently "work", meaning that if I type them into the address bar in the form below, I
- a) see the correct content
- b) see them unchanged and in the form below in the address bar after the page loads

example.com/cash
example.com/blacktigrex


2. The URLs on your site - in the navigation and everything - are in the form

example.com/index.php/streams/cash


If that's the case, there's no mod_rewrite fu in the world that can correct that problem in a .htaccess file. You need to correct your output on the Joomla end.

If that is not the case, I'm sorry, but I'm just not following your answers.

RobbyBubble




msg:4556845
 3:03 pm on Mar 20, 2013 (gmt 0)

Regarding lucy24's post I just need two commands.

RewriteRule XYZXYZXYZXYZ
Redirect XYZXYZXYZXYZXYZ

I'll never touch a htaccess file again so I'm not really interested in getting into it.

g1smd




msg:4556850
 3:34 pm on Mar 20, 2013 (gmt 0)

If you're not going to be "getting into it" then this forum is, unfortunately, not for you. Its whole rationale is to help you to learn to "get into it". There are not enough volunteers here to provide a free code writing service. There are, however, 80 000 previous threads covering every aspect of htaccess - some popular topics having been covered several hundreds of times or more.

Time spent here is only an investment to posters if knowledge and learning is transferred and seen to be gained... "teach a man to fish" and all that. Providing free code, especially to people already being paid to do a job (as has happened in the past), is a resource sink with no benefit to the forum or the poster.

You'll need to find someone to take this on as a paid job, but you'll need to provide a very detailed specification otherwise what you get might not be quite what you wanted.

[edited by: g1smd at 4:02 pm (utc) on Mar 20, 2013]

ergophobe




msg:4556851
 3:41 pm on Mar 20, 2013 (gmt 0)

You didn't answer my questions or g1smd's questions which are essential to understanding your problem and therefore to offering a solution.

I'm not really interested in getting into it.


Statements like that will not motivate volunteer helpers giving time for free to "get into it" for you. Did you even read my post? We are not trying to be difficult, but we need a clear understanding of what's happening on the site. Based on what you said to Andy_Langton, no RewriteRule is going to help.

Read my post and g1smd's posts *carefully* and respond fully to the questions in them, and then we might be able to sort this out *with* you.

RobbyBubble




msg:4556861
 4:05 pm on Mar 20, 2013 (gmt 0)

I'm searching for a soluition for 2 weeks. I already posted in 5 german joomla forums, opened 4 questions on stackoverflow.com, were chatting 4 hours with the joomla live support und now I'm here.
NOBODY was able to help me or able to undestand my problem. Everybody is telling me things I alreday know like "Did you enable URL-Rewrite?" or is giving me broken commands.

I won't do anything further for it. I'm not a programmer.

Everythings startet with a friend who said "cant copy my stream url in my away cause its too long!".

[edited by: ergophobe at 9:35 pm (utc) on Mar 20, 2013]
[edit reason] please be civil [/edit]

g1smd




msg:4556871
 4:24 pm on Mar 20, 2013 (gmt 0)

None of the above answers the specific questions about the site functionality that were previously asked.

This stuff is difficult. We get that. It's difficult to understand. We get that. However, we can't read your mind.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Content Management
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved