Forum Moderators: phranque

Message Too Old, No Replies

htacess rewrite for SEF url and another app

can i do both in the same htaccess file

         

malady

5:25 am on Apr 14, 2007 (gmt 0)

10+ Year Member



quick question as I'm really rather green to the webmaster stuff and my programmer is off getting married so I'm on my own for a week and can't wait.

We developed a large custom joomla based website in a back directory while we built our social networking site in the root folder. Now that we are finished with the joomla based front end we moved it into root and everything is fine except the htaccess.

we have the rewrite rule on for the profiles of the social network so it will go to their custom urls they set.. BUT in the joomla I need to have some rewrites in there for the search engine friendly urls.

what we currently have in there now looks like this

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
#RewriteRule ^(.*)$ url_redir.php?display_url=$1
RewriteRule ^(.*)$ view_profile.php?display_url=$1

and i need to keep that for the social networking stuff but i need to add in basically the same thing with just different rewrite rule stuff from the SEF htaccess.

Is there any way to get it to do both?

malady

5:38 am on Apr 14, 2007 (gmt 0)

10+ Year Member



sorry the code i need to add in there is


RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR] ##optional - see notes##

RewriteCond %{REQUEST_URI} (/¦\.htm¦\.php¦\.html¦/[^.]*)$ [NC]

RewriteCond %{REQUEST_FILENAME}!-f

RewriteCond %{REQUEST_FILENAME}!-d

RewriteRule (.*) index.php

it seems like i can only have one or the other :(

jd01

4:39 pm on Apr 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI}!^/component/option [NC,OR] ##optional - see notes##
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
#RewriteRule ^(.*)$ url_redir.php?display_url=$1
RewriteRule ^(.*)$ view_profile.php?display_url=$1

RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR] ##optional - see notes##
RewriteCond %{REQUEST_URI} (/¦\.htm¦\.php¦\.html¦/[^.]*)$ [NC]
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule (.*) index.php

You might have a try with something like the above. Please note it is wholly inefficient. The best advice I could give is to use some sort of "standardized" naming convention to determine if a request should be rewritten, rather than the "is it a file" (%{REQUEST_FILENAME} !-f) and "is it a directory" (%{REQUEST_FILENAME} !-d) conditions.

EG
RewriteCond %{REQUEST_URI}!^/component/option [NC,OR] ##optional - see notes##
RewriteCond %{REQUEST_URI}!^/your-actual-directory/
#RewriteRule ^(.*)$ url_redir.php?display_url=$1
RewriteRule ^(.*)$ view_profile.php?display_url=$1

Of course, matching depends on the naming convention you use for *actual* directories/files.

Justin

malady

4:51 pm on Apr 14, 2007 (gmt 0)

10+ Year Member




"Of course, matching depends on the naming convention you use for *actual* directories/files. "

Both are in the root directory of the site

malady

4:54 pm on Apr 14, 2007 (gmt 0)

10+ Year Member



I tried what you put above and got a server error.

jd01

5:34 pm on Apr 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, I didn't check your post count.
Welcome to WebmasterWorld!

Make sure you change the ¦ to a solid bar when you copy/paste. (The forum software changes a "bar" to a "broken bar".)

Make sure you add back the spaces between the closed } and the !. ("Punctuation" characters are moved "one space left" when posting, so if we forget to "double space" between a closed } and a ! they will be next to each other.)

I have not tested the code, just given an example. We try to avoid "writing code" on demand, because the supply of "code writers" is much smaller the the "need code writteners", so we prefer to point in a direction.

If you are still getting errors, please check your server logs and post an *examplified* version of the error you are receiving when implementing the code and we will try to help you from there.

Justin

malady

11:03 pm on Apr 14, 2007 (gmt 0)

10+ Year Member



After fixing the punctuation and the lines, I checked the error logs and got a bad flag delimiters error under rewrite conditions.

I'm not a programmer at all, so to be honest I have no clue what that even means. I just know that you cant click on any links on the homepage because the SEF has changed the urls and they go to file not found.

Since both the CMS and the Social Portal are housed in the root directory I'm not really sure how to proceed. The social networking on has one url type that needs to be redirected whereas all the urls for the articles, news, music etc in the CMS needs to be search engine friendly. Sadly the one social network url needs to stay as it is or 50k peoples personal url link will no longer work and we have a ton of link backs because of them.

I'm kinda stuck.

jd01

1:33 am on Apr 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would suggest going back to the original and waiting for your programmer, because other than 'guessing' and 'throwing darts' it's going to be very difficult for us to try and solve your problem.

The flag delimiter error should be related to the -d and/or -f respectively.

I wish I could be of more help.
Maybe someone else can, or has some ideas which are not 'popping' into my head?

Justin

malady

2:16 am on Apr 15, 2007 (gmt 0)

10+ Year Member



waiting for my programmer is not an option. I'm willing to pay someone to fix this issue for me or sit here trying to understand this code stuff until I figure it out myself. I need to learn it anyway.

jdMorgan

2:29 am on Apr 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I haven't contributed here because based on my understanding of what you've posted, there's no way to discriminate between the SEF URLs and the others, or between the SEF files and the others. Without something in the URLs or the filepaths for mod_rewrite to 'grab onto,' I don't see a solution to the problem with all of your stated constraints.

I'd recommend putting the joomla content back into its subdirectory to solve the problem. Remember that just because the joomla *files* are stored in a subdirectory, that does not mean that the URLs need to reflect or expose that subdirectory. As mod_rewrite makes clear, URL-paths and filenames are not at all the same thing, and in fact, need have nothing in common.

mod_rewrite will need some kind of uniquely-identifiable information derived from the URL-path or the filepath, to determine which RewriteRules to apply.

Jim

malady

2:37 am on Apr 15, 2007 (gmt 0)

10+ Year Member



thanks jdMorgan

Quick question then, if I place the Joomla back in the subdirectory which would be simple to do, what would I need to place in the htacess to call those files like they are in the root?

malady

2:38 am on Apr 15, 2007 (gmt 0)

10+ Year Member



ehh lemme try to clarify what i mean. If I place the joomla files back in the subdirectory how do i get them to show up when you call www.sitename.com and not show the subdirectory anywhere in the url?

jdMorgan

2:47 pm on Apr 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To demonstrate the concept, with the SEF invocation details probably not quite right:

# If file exists in joomla directory (prepend document root and joomla path to the request-URI, then check it)
RewriteCond %{DOCUMENT_ROOT}/joomla_directory/$1 -f
# then internally rewrite the request to that directory
RewriteRule (.*) /joomla_directory/$1 [L]
#
# Else assume it's an SEF URL
RewriteRule (.*) /SEF_files/$1 [L]

If possible, you would want to further restrict the requests that can match the first rule, by using a more restrictive pattern based on filetype or by any other URL-based information available. File-exists checks are relatively slow, and should be avoided when reasonably easy and possible.

Jim