regular expressions and mod_rewrite - please help

New to mod_rewrite? This is a good place to start.

regular expressions and mod_rewrite - please help

Postby oswald_yang » Thu Oct 29, 2009 7:31 am

Hey Guys,

Apologies for this 'possibly' noob question. I've written basic mod_rewrite rules which works well, but there is one I can't seem to get working. I've tried many rules, looked at many examples, but to no avail and now that deadline is tomorrow, I'm getting desperate. So what I want to happen is this:

http://sub.domain.com/foo/bar/page?s=32 ... ifications
...needs to become...
http://sub.domain.com/page?s=3263,0,0,0 ... ifications

NOTE: "3263,0,0,0,177,0,Qualifications" changes with every page - the numbers and words.

This is where I'm at now. I know it's wrong, just have NO idea what to do about it or how it should look (ie. to remove "/foo/bar/ and keep the rest).

RewriteEngine On
RewriteRule ^([^/]*)\$ /foo/bar/page?s=$1 [L]

Thanks,
Charl
oswald_yang
 
Posts: 4
Joined: Thu Oct 29, 2009 7:17 am

Postby oswald_yang » Fri Oct 30, 2009 5:54 am

Hey Guys,

Not sure if posting a question like the above is bad forum etiquette (hope it's not), but I am rather desperate. I have this deadline for tonight (south african time - 4 hours to go) to get this sorted. Really I've tried just about anything IRC, you name it, but to no avail.

My sincere apologies to sound so desperate, but I am. Can someone at least tell me whether what I'm trying to do is possible or not?

Any assistance would be GREATLY appreciated!

Thanks,
Charl
oswald_yang
 
Posts: 4
Joined: Thu Oct 29, 2009 7:17 am

Postby richardk » Fri Oct 30, 2009 11:23 am

Does "page" change?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?s=.
RewriteRule ^([^/]+)/?$ /foo/bar/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby oswald_yang » Mon Nov 02, 2009 12:46 am

Hey Richard,

Thanks for replying! No, 'page' does not change. The only part that changes is:

"3263,0,0,0,177,0,Qualifications"

I tried the code you sent (changed the foo and bar to what they should be) in an .htaccess file and in the vhost, but it didn't have any effect, AllowOverride is set to All and mod_rewrite is enabled as we use it on many other sites.

I think the problem might be the following... In the vhosts root dir there are only two files, .htaccess and index.htm, the vhost itself contains the following line:

Redirect permanent /index.htm http://foo.bar.domain.co.za/foo/bar/pag ... ,0,0,177,0,

The content of the site is pulled from our cms' Oracle DB cache with the use of mod_plsql, ie. the sites content aren't in the sites root dir - do you think this might be the reason why the rewrite rules have no effect and if so, any ideas on how to over come this issue?

(I know that Redirect and Rewrite can't work in conjunction, so I have tried removing the Redirect rule and tested without it and still no luck.)
oswald_yang
 
Posts: 4
Joined: Thu Oct 29, 2009 7:17 am

Postby richardk » Mon Nov 02, 2009 10:38 am

What URL is currently in the browser's address bar?
What URL should be in the browser's address bar?
What is the actual URL to the content?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?s=.
RewriteRule ^/page/?$ /foo/bar/page [QSA,L]

and
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?s=.
RewriteRule ^/foo/bar/page/?$ /page [R=301,L]

in your <VirtualHost>.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby oswald_yang » Tue Nov 03, 2009 12:38 am

Hi Richard,

Thanks again for your assistance, I tried both suggestions (and obviously replaced foo and bar with their REAL entries), but still no luck, tried both in the .htaccess file and the URL doesn't budge, BUT adding them to the vhost, the first option does nothing, but the second changes the URL to look like it should, but also seems to want to load modified URL, which obviously doesn't exist.

So to answer you questions:

What URL is currently in the browser's address bar?

Let's explain using the actual URL's. When I enter
Code: Select all
http://nqf.pl.privatelabel.co.za/

into my browser, it jumps to (which is what it should load)
Code: Select all
http://nqf.pl.privatelabel.co.za/pls/cms/page?s=3263,0,0,0,177,0,

and whatever page's one clicks on adds the respective page name, ie. Qualifications to the end of the URL.

What URL should be in the browser's address bar?

actual URL
Code: Select all
http://nqf.pl.privatelabel.co.za/pls/cms/page?s=3263,0,0,0,177,0,

should display
Code: Select all
http://nqf.pl.privatelabel.co.za/page?s=3263,0,0,0,177,0,

and actual URL
Code: Select all
http://nqf.pl.privatelabel.co.za/pls/cms/page?s=3263,0,0,0,177,0,Qualifications

should display
Code: Select all
http://nqf.pl.privatelabel.co.za/page?s=3263,0,0,0,177,0,Qualifications


If it's easier for the pages to display the following options (respective to the above) we can go for that.

Code: Select all
http://nqf.pl.privatelabel.co.za/

Code: Select all
http://nqf.pl.privatelabel.co.za/Qualifications


What is the actual URL to the content?

Please see above...

It does seem like were getting somewhere :) I've removed rewrite rules from the vhost for the time being as it kills the temp site.

Cheers,
Charl
oswald_yang
 
Posts: 4
Joined: Thu Oct 29, 2009 7:17 am


Return to Beginner's Corner

Who is online

Users browsing this forum: Google [Bot] and 30 guests

cron