batch 301 redirect
Last Post 09/08/2016 12:39 AM by Prasoon. 3 Replies.
Author Messages
Prasoon
Nuke Newbie
Nuke Newbie
Posts:1


--
08/26/2016 1:45 AM  
I have some url with /dev in them I want to drop /dev from url so that they can go to production. how do I drop the string /dev from the url. There are hundreds of dev url that need to point to production.

I want to drop dev and keep rest of the string after dev because in production the same page is a copy except that "dev" is omitted.

Thanks
Andy Stephenson DNN Creative
DNN Creative Staff
Nuke Master VI
Nuke Master VI
Posts:169


--
09/01/2016 9:43 AM  
I am assuming the "dev/" that needs to be removed is part of the content of the HTML module. If so, you can use the following script to get rid of it.

Note: Make sure you back up your Database before trying this

	SET NOCOUNT ON; 
	DECLARE 
	    @TextPointer BINARY(16), 
	    @TextIndex INT, 
	    @oldString NVARCHAR(200), 
	    @newString NVARCHAR(200), 
	    @lenOldString INT, 
	    @currentDataID INT; 

	SET @oldString = N'dev/'; 
	SET @newString = N'';  

	IF CHARINDEX(@oldString, @newString) <= 0  
	BEGIN 
	    SET @lenOldString = DATALENGTH(@oldString)/2;

	    DECLARE irows CURSOR 
		LOCAL FORWARD_ONLY STATIC READ_ONLY FOR 

	    SELECT ItemID
	    FROM [dbo].[HTMLText]
	    WHERE PATINDEX(&#39;%&#39;+@oldString+&#39;%&#39;, [Content] ) > 0; 

	    OPEN irows; 

	    FETCH NEXT FROM irows INTO @currentDataID; 

	    WHILE (@@FETCH_STATUS = 0) 
	    BEGIN 

		SELECT 
		    @TextPointer = TEXTPTR([Content] ),  
		    @TextIndex = PATINDEX(&#39;%&#39;+@oldString+&#39;%&#39;, [Content] ) 
		FROM 
		    [dbo].[HTMLText]
		WHERE 
		    ItemID = @currentDataID; 

		WHILE 
		( 
		    SELECT 
			PATINDEX(&#39;%&#39;+@oldString+&#39;%&#39;, [Content] ) 
		  FROM 
		    [dbo].[HTMLText] 
		    WHERE 
			ItemID = @currentDataID 
		) > 0 
		BEGIN 
		    SELECT 
			@TextIndex = PATINDEX(&#39;%&#39;+@oldString+&#39;%&#39;, [Content] )-1 
		    FROM 
			 [dbo].[HTMLText]
		    WHERE 
			ItemID = @currentDataID; 

		    UPDATETEXT [dbo].[HTMLText].[Content] @TextPointer @TextIndex @lenOldString @newString; 
		END 

		FETCH NEXT FROM irows INTO @currentDataID; 
	    END 

	    CLOSE irows; 

	    DEALLOCATE irows; 
	END
	go
Joseph Craig
DNN MVP
Posts:11667


--
09/01/2016 11:41 AM  
The free Evotiva Search and Replace module might be a safer, and easier, tool to use here. You can find it at http://www.evotiva.com/Downloads.

Still, you should always make a backup before doing and major work to your site.

Joe Craig, Patapsco Research Group
Complete DNN Support
Prasoon
Nuke Newbie
Nuke Newbie
Posts:1


--
09/08/2016 12:39 AM  
Her's what I am trying to do..... redirect a bad url to a page





Does not work...any ideas? thanks


---