Reply New Topic
2008/12/31 6:58:17
#1
Offline
Not too shy to talk

site.com/content.php?page=XXX to site.com/XXX

Hello,

I want to change my site.com/content.php?page=XXX links to site.com/XXX , with using Rewriting Url.

What is the code that i've to use to do that !

thank you


2008/12/31 8:53:45
#2
Offline
Not too shy to talk

Re: site.com/content.php?page=XXX to site.com/XXX

yes this is the optimal rewrite engine, but at the moment not doable ...
maybe later with an impresscms node system.

_________________
online shop | ImpressCMS Blog

2008/12/31 9:26:33
#3
Offline
Home away from home

Re: site.com/content.php?page=XXX to site.com/XXX

why isn't it doable?

Shouldn't this work just fine?
RewriteRule ^content.php?page=XXX$ /XXX/ [R]


2008/12/31 9:51:18
#4
Offline
Just can not stay away

Re: site.com/content.php?page=XXX to site.com/XXX

If you can use rewrite rules all you need is a little bit of hacking actually.

1. Check if the url is a valid url. If so then don't do anything.
2. If not a valid url: rewrite the url from site.com/XXX to site.com/content.php?page=XXX

.htaccess code should be something like:
Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([a-zA-Z0-9_]*)$ content.php?page=$1 [NC,L]


This has not been tested yet but you can give it a try. On the following link you can find a few useful examples:

http://httpd.apache.org/docs/1.3/misc/rewriteguide.html


2008/12/31 9:56:11
#5
Offline
Home away from home

Re: site.com/content.php?page=XXX to site.com/XXX

I was just playing around with it - and its totally possble - this is actually working code. Modify to your needs.

Options +FollowSymlinks RewriteEngine on RewriteRule ^content/([^/]+)$ /content.php?page=$1 [P,NC]


You are going to need an identifier like /content/ or /page/ otherwise anything that comes after your domain is going to be forced into the loop.

i.e. http://www.yoursite.com/modules... will become http://www.yoursite.com/content.php?page=modules...

so if you use the "content" or "page" identifier it would prevent this.

Edit: See Below


2008/12/31 10:02:10
#6
Offline
Just can not stay away

Re: site.com/content.php?page=XXX to site.com/XXX

Quote:

You are going to need an identifier like /content/ or /page/ otherwise anything that comes after your domain is going to be forced into the loop.



Yes, logfically the procedure could be:

1. check if url exists, if true then don't rewrite the url
2. If url does not exist: use rewrite rule

I have read on a site that #1 is done by:
RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f


2008/12/31 10:06:22
#7
Offline
Home away from home

Re: site.com/content.php?page=XXX to site.com/XXX

makes sense to me, and you are correct - so the final working code is

Options +FollowSymlinks RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)$ /content.php?page=$1 [P,NC]


2008/12/31 11:26:32
#8
Offline
Just can not stay away

Re: site.com/content.php?page=XXX to site.com/XXX

Excellent, now the next step would be to generate SEO friendly links from the content manager itself. Meaning that all links in the content menu for example should be conforming the SEO friendly way. Preferrably this should be based on a variable configuration parameter.

Quick and dirty would be something like:

If admin choses to use the rewrite rule in a .htaccess file, all url's to content pages should be rewritten from: site.com/content.php?page=XXX to site.com/XXX

In order to do that we need to change the files:
content.php
modules/system/blocks/content_blocks.php
include/functions.php

In the first two files change the line:
$content_subs['link'] = ICMS_URL.'/content.php?page='.$seo;

to:
$content_subs['link'] = ICMS_URL.'/'.$seo;


In include/functions.php in function showNav() change the line:
$url = ICMS_URL.'/content.php';

into:
$url = ICMS_URL.'/'

And the line:
$ret = "<a href='".$url."?page=".$seo."'>".$cont->getVar('content_title')."</a>";

into:
$ret = "<a href='".$url.$seo."'>".$cont->getVar('content_title')."</a>";


2008/12/31 11:46:00
#9
Offline
Home away from home

Re: site.com/content.php?page=XXX to site.com/XXX

very cool - i did run into a little problem with accessing my domain if I didn't have anything trailing.

So mysite.com/ would redirect to the content manager and say "page does not exist - then send me to index.php

A rule would need to be added for the toplevel.


2008/12/31 15:42:54
#10
Offline
Not too shy to talk

Re: site.com/content.php?page=XXX to site.com/XXX

Your Latest code MrTheme doesnt work, it give 404 error


2008/12/31 15:52:50
#11
Offline
Not too shy to talk

Re: site.com/content.php?page=XXX to site.com/XXX

this code works perfectly for me :

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^content/(.*)/$ /content.php?page=$1 [L] RewriteRule ^content/(.*)$ /content.php?page=$1 [L]


2008/12/31 20:05:33
#12
Offline
Home away from home

Re: site.com/content.php?page=XXX to site.com/XXX

odd - works fine for me. perhaps Proxy Throughput is conflicting with something on your server.

Anywho, glad you got a solution that works for you.


2009/1/1 3:01:21
#13
Offline
Not too shy to talk

Re: site.com/content.php?page=XXX to site.com/XXX

Thanks for your help


2009/1/1 7:53:15
#14
Offline
Not too shy to talk

Re: site.com/content.php?page=XXX to site.com/XXX

great tips, very helpful ... thank you.

_________________
online shop | ImpressCMS Blog

2009/2/3 9:39:58
#15
Offline
Quite a regular

Re: site.com/content.php?page=XXX to site.com/XXX

Hello there!

the tips are really nice.

I'm trying to apply this rewrite using my localhost and xampp 1.7 (php 5.28) and I'm not getting any response from localhost on the changes.

I already checked over the loadmodule line under http.conf and uncommented it and restarted apache but I can't get it to run.

Anyone has tips on how to go over this?

Thanks

Eyekeeper


2009/2/12 9:17:01
#16
Offline
Quite a regular

Re: site.com/content.php?page=XXX to site.com/XXX

any ideas, plz?


2009/2/12 10:42:38
#17
Offline
Home away from home

Re: site.com/content.php?page=XXX to site.com/XXX

LoadModule auth_passthrough_module modules/mod_auth_passthrough.so


2009/2/13 7:38:24
#18
Offline
Quite a regular

Re: site.com/content.php?page=XXX to site.com/XXX

Hello!

thanks for the reply
I googled for this file but I can't get the "so" downloaded...
I find it nowhere so I could test it...

Do you know where to get it?

Thanks once again


2009/2/13 9:13:24
#19
Offline
Home away from home

Re: site.com/content.php?page=XXX to site.com/XXX

I am sorry - I copied the wrong line.

LoadModule rewrite_module modules/mod_rewrite.so

is that the line that you uncommented?

what apache version are you running?

There may be a call to AddModule mod_rewrite.c as well that you would have to have uncommented.

Then of course you need to make sure that the module is actually there.

more info:
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

Also did you make sure that htaccess was enabled?


2009/2/14 6:50:42
#20
Offline
Quite a regular

Re: site.com/content.php?page=XXX to site.com/XXX

Quote:


MrTheme wrote:
I am sorry - I copied the wrong line.


no problem ;)

Quote:


is that the line that you uncommented?


yes...this line was already uncommented

Quote:


what apache version are you running?


using Xampp I use following

Apache HTTPD 2.2.11 + Openssl 0.9.8i
MySQL 5.1.30
PHP 5.2.8

Quote:


There may be a call to AddModule mod_rewrite.c as well that you would have to have uncommented.


there isn't this call as well

All the rest should be fine...

I don't know further


Reply New Topic extras
 Previous Topic   Next Topic
You can view topic.
You can start a new topic.
You can reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You can post without approval.