Jump to content

[SOLVED] SEF URIs problem


Fadion

Recommended Posts

I know this is not the correct section, but i saw that the mod_rewrite secion of apache doesnt get too many hits and i need to fix this thing quick :S

 

Im trying to make my urls search engine friendly, but im having problems. My urls look like:

 

1. http://www.domain.com/index.php?g=a

2. http://www.domain.com/index.php?g=a&artist=Someone

3. http://www.domain.com/index.php?g=a&artist=Someone&song=Something

 

I made three rules for each specific combination:

 

RewriteRule index/(.*).html /index.php?g=$1

RewriteRule index/(.*)/(.*).html /index.php?g=$1&artist=$2

RewriteRule index/(.*)/(.*)/(.*).html /index.php?g=$1&artist=$2&song=$3

 

The first rule is working as when i go to a url like "www.domain.com/index/a.html" it shows the correct stuff, but the other two rules dont show anything. Tried what i was able to do, but no success.

 

Another problem is that when i go in a url like "www.domain.com/index/a.html" the styles, images and stuff dont show. I have them in specified folders in root and are called relatively, so this SEF thing is breaking the links. I could go and make every link absolute but that would be a not so cool method, so i though there's something better. Im pretty new to this so any help would be appriciated.

 

Thank you.

Link to comment
Share on other sites

I realised that my first rule: "RewriteRule ^index/(.*).html$ /index.php?g=$1" stopped the other rules from working correctly. Meaning that when i type a url "index/a.html" it works ok, but when i type "index/someone/file.html" it get "someone/file.html" as a single variable for my first rule.

 

I have another question. I have all my links generated with php which point to not SEF urls, like "index.php?g=a". With my basic understanding, i thought those urls would be translated automatically to SEF which normaly isnt happening. Do i have to modify the script to show urls like "index/a/something/anything/"?

Link to comment
Share on other sites

I realised that my first rule: "RewriteRule ^index/(.*).html$ /index.php?g=$1" stopped the other rules from working correctly. Meaning that when i type a url "index/a.html" it works ok, but when i type "index/someone/file.html" it get "someone/file.html" as a single variable for my first rule.

 

I have another question. I have all my links generated with php which point to not SEF urls, like "index.php?g=a". With my basic understanding, i thought those urls would be translated automatically to SEF which normaly isnt happening. Do i have to modify the script to show urls like "index/a/something/anything/"?

 

That's correct.  You will have to modify the scripts to rewrite those URL's.  The "old" URL's will still be valid as it's not requiring the .htaccess file to do any rewriting and it will be parsed as a normal URL... might I suggest that you actually set something up in a config file to enable the URL's to still be generated in the non-SEF format with the flick of a hypothetical switch?  This way, if you ever move servers and they don't support .htaccess (which is a performance sacrificing ability) you will be able to re-enable non-SEF URL's.

Link to comment
Share on other sites

After a lot of reading and experimenting, finally i achieved what i wanted. The three rules i have now are:

 

RewriteRule ^([^/]+)\.html$ /index.php?g=$1 [L]

RewriteRule ^([^/]+)/([^/]+)\.html$ /index.php?g=$1&artist=$2 [L]

RewriteRule ^([^/]+)/([^/]+)/([^/]+)\.html$ /index.php?g=$1&artist=$2&song=$3 [L]

 

I had the regex "(.*)" initally which was blocking the other rules. I modified it with "([^/]+)" which will bypass the rule if there is any "/" in the url. I had also the problem of the rewritten urls of styles and images. Tried to exclude them with RewriteCond but didnt work. Finally i realised that adding a slash before them (ex: "/styles.css" instead of "styles.css") did the trick. Now its working like a charm.

 

@jellis, thnx for the reply. Didnt have any idea about mod_rewrite, but now i have things a bit more clear. I understand that i have to modify the script, but it isnt very much a problem. Your suggestion of having SEF and not-SEF friendly urls is a good idea. I have to think how to easily do it, but i think its easy enough.

 

Hope these help someone who has the same problems.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.