strip portion of url then 301

Discuss practical ways rearrange URLs using mod_rewrite.

strip portion of url then 301

Postby mindhunter77 » Mon Oct 13, 2008 4:56 pm

I'm new to this but I can't seem to figure out how to do this


this is the URL structure

Code: Select all
/forum/gallery/browseimages.php?c=38&userid=


Now I would like to remove the

Code: Select all
&userid=


I'm lost lol..

Also, the number (in this case 38 ) will be different most of the time.
mindhunter77
 
Posts: 3
Joined: Mon Oct 13, 2008 4:50 pm

Postby richardk » Tue Oct 14, 2008 9:46 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^((.*&)?c=.+)&userid=$ [NC,OR]
RewriteCond %{QUERY_STRING} ^userid=&((.*&)?c=.+)$ [NC]
RewriteRule ^(forum/gallery/browseimages\.php)$ /$1?%1 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mindhunter77 » Tue Oct 14, 2008 1:28 pm

it didn't work, no error message or anything, just didn't do anything.

I'm not entirely sure your code is wrong though. Going to play with some settings and use this code you gave me as a guide.
mindhunter77
 
Posts: 3
Joined: Mon Oct 13, 2008 4:50 pm

Postby richardk » Tue Oct 14, 2008 2:41 pm

Where are you putting the mod_rewrite? It should go in a .htaccess file in your document root (it can be changed to work in sub directories).

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(?:(.*)&)?userid=&?$ [NC,OR]
RewriteCond %{QUERY_STRING} ^&?userid=&(.+)$ [NC,OR]
RewriteCond %{QUERY_STRING} ^(.+)&userid=&(.+)$ [NC]
RewriteRule ^(forum/gallery/browseimages\.php)$ /$1?%1%2 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mindhunter77 » Tue Oct 14, 2008 2:58 pm

Yea, I am placing it in the domain root,

This is what I have in .htaccess in the domain root

Code: Select all
RewriteEngine On
Options -Indexes
Options +FollowSymLinks
ErrorDocument 404 /forum

RewriteCond %{http_host} ^documentingreality.com [NC]
RewriteRule ^(.*)$ http://www.documentingreality.com/$1 [R=301,L]

Redirect 301 /feed http://www.documentingreality.com/forum/external.php
Redirect 301 /forums/ http://www.documentingreality.com/forum/
Redirect 301 /images/spitzer http://www.documentingreality.com/forum/gallery/browseimages.php?c=14
Redirect 301 /iraq-war-images http://www.documentingreality.com/forum/f152/
Redirect 301 /iraq-war-images/ http://www.documentingreality.com/forum/f152/
Redirect 301 /courtroom-fight-videos http://www.documentingreality.com/forum/f57/
Redirect 301 /video http://www.documentingreality.com/forum/f57/
Redirect 301 /27/woman-has-the-ability-to-double-her-pleasure/ http://www.documentingreality.com/forum/f149/woman-has-two-vaginas-10631/
Redirect 301 /images/jennifer-love-hewitt-fat-1.jpg http://www.documentingreality.com/forum/f3/jennifer-love-hewitt-fat-beach-pictures-9049
Redirect 301 /images/jennifer-love-hewitt-fat-2.jpg http://www.documentingreality.com/forum/f3/jennifer-love-hewitt-fat-beach-pictures-9049
Redirect 301 /images/jennifer-love-hewitt-fat-3.jpg http://www.documentingreality.com/forum/f3/jennifer-love-hewitt-fat-beach-pictures-9049
Redirect 301 /images/jennifer-love-hewitt-fat-4.jpg http://www.documentingreality.com/forum/f3/jennifer-love-hewitt-fat-beach-pictures-9049
Redirect 301 /images/jennifer-love-hewitt-fat-5.jpg http://www.documentingreality.com/forum/f3/jennifer-love-hewitt-fat-beach-pictures-9049
Redirect 301 /images/jennifer-love-hewitt-fat-6.jpg http://www.documentingreality.com/forum/f3/jennifer-love-hewitt-fat-beach-pictures-9049
Redirect 301 /images/jennifer-love-hewitt-fat-7.jpg http://www.documentingreality.com/forum/f3/jennifer-love-hewitt-fat-beach-pictures-9049
Redirect 301 /images/jennifer-love-hewitt-fat-8.jpg http://www.documentingreality.com/forum/f3/jennifer-love-hewitt-fat-beach-pictures-9049
Redirect 301 /forum/f134/ http://www.documentingreality.com/forum/gallery/browseimages.php?c=6
Redirect 301 /forum/attachments/f2/8780d1171471228-33-weird-unusual-shaped-houses-around-world-saucer-house-santa-monica-blvd-west-hollywood.jpg http://www.documentingreality.com/forum/f2/33-weird-unusual-shaped-houses-around-world-2456/
Redirect 301 /images/c/chs.jpg http://www.documentingreality.com/forum/f10/columbine-8295/

RewriteRule ^((urllist|sitemap).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]

RewriteCond %{QUERY_STRING} ^(?:(.*)&)?userid=&?$ [NC,OR]
RewriteCond %{QUERY_STRING} ^&?userid=&(.+)$ [NC,OR]
RewriteCond %{QUERY_STRING} ^(.+)&userid=&(.+)$ [NC]
RewriteRule ^(forum/gallery/browseimages\.php)$ /$1?%1%2 [R=301,L]




There is another .haccess in /forum as well

Code: Select all
# Comment the following line (add '#' at the beginning)
# to disable mod_rewrite functions.
# Please note: you still need to disable the hack in
# the vBSEO control panel to stop url rewrites.
RewriteEngine On
Options +FollowSymLinks

# Some servers require the Rewritebase directive to be
# enabled (remove '#' at the beginning to activate)
# Please note: when enabled, you must include the path
# to your root vB folder (i.e. RewriteBase /forums/)
#RewriteBase /

#RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com
#RewriteRule (.*) http://www.yourdomain.com/forums/$1 [L,R=301]

RewriteRule ^((urllist|sitemap).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]

RewriteCond %{REQUEST_URI} !(ads/|admincp/|modcp/|cron|vbseo_sitemap)
RewriteRule ^((archive/)?(.*\.php(/.*)?)?)$ vbseo.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^(admincp|modcp|clientscript|cpstyles|images|gallery|adserver)/
RewriteRule ^(.+)$ vbseo.php [L,QSA]

RewriteRule ^view_(.*).htm$ view.php?pg=$1
mindhunter77
 
Posts: 3
Joined: Mon Oct 13, 2008 4:50 pm

Postby richardk » Wed Oct 15, 2008 6:31 am

Try adding
Code: Select all
RewriteCond %{QUERY_STRING} ^(?:(.*)&)?userid=&?$ [NC,OR]
RewriteCond %{QUERY_STRING} ^&?userid=&(.+)$ [NC,OR]
RewriteCond %{QUERY_STRING} ^(.+)&userid=&(.+)$ [NC]
RewriteRule ^(gallery/browseimages\.php)$ /forum/$1?%1%2 [R=301,L]

after
Code: Select all
RewriteEngine On

in /forum/.htaccess.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 10 guests

cron