homepage Welcome to WebmasterWorld Guest from 54.204.215.209
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
redirect dynamic page
how to do it?
liorsi




msg:4577334
 10:34 am on May 24, 2013 (gmt 0)

hey

i am trying to redirect my old url to the new one:

http://www.example.com/Front/Pages/pages.asp?id=42498

to
http://www.example.com/index.php/food-tours


i tried this:

RewriteCond %{QUERY_STRING} id=42498
RewriteRule \/Front/Pages/pages.asp http://www.example.com/index.php/food-tours? [R=301]


it's not working.

somebody know how to make it right?
and how much time it's take to apply rewrite like this (if it's correct)?

the new site is a joomla site. i pasted this code in the original Joomla htaccess. mebay it's not working together?

thanks.

[edited by: phranque at 1:16 pm (utc) on May 24, 2013]
[edit reason] please use example.com [/edit]

 

phranque




msg:4577411
 1:24 pm on May 24, 2013 (gmt 0)

welcome to WebmasterWorld, liorsi!

when you say it's not working you really should describe the response you got.

if this code is used in .htaccess there will be no leading slash in the path, so your pattern will fail to match.


unrelated to your problem, you should ditch the index.php/ in urls but that will probably require a joomla config change

liorsi




msg:4577426
 2:00 pm on May 24, 2013 (gmt 0)

this is the error i get when i enter to the old link:
Not Found

The requested URL /Front/Pages/pages.asp was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Apache Server at www.example.com Port 80

[edited by: tedster at 3:07 pm (utc) on May 24, 2013]

liorsi




msg:4577431
 2:08 pm on May 24, 2013 (gmt 0)

and where i need to insert the rewrite in the this htaccess file? (joomla default file)

##
# @packageJoomla
# @copyrightCopyright (C) 2005 - 2013 Open Source Matters. All rights reserved.
# @licenseGNU General Public License version 2 or later; see LICENSE.txt
##

##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations. It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file. If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's. If they work,
# it has been set by your server administrator and you do not need it set here.
##

## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks

## Mod_rewrite in use.

RewriteEngine On

## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects

##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##

# RewriteBase /

## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.

phranque




msg:4577476
 4:41 pm on May 24, 2013 (gmt 0)

put the ruleset in the custom redirects section.

and get rid of the leading slash in your RewriteRule pattern.

lucy24




msg:4577500
 5:14 pm on May 24, 2013 (gmt 0)

overlapping phranque
this is the error i get when i enter to the old link:

Good. That means it "isn't working" in the purest sense: the redirect simply isn't taking place at all. I say "good" because these are generally the easiest to fix.

RewriteRule \/Front/Pages/pages.asp http://www.example.com/index.php/food-tours? [R=301]

This rule actually contains four errors: one fatal, two dangerous and one presentational.

"Fatal" = it will prevent the rule from working, not "fatal" = it will crash the site ;) That's the leading slash already discussed.

Dangerous error #1: the unescaped literal period in .asp. Most of the time this will have no effect, because requests will have a . in this location. But if someone types in-- or a Ukrainian robot asks for--
pageszasp
or
pages,asp
or similar, you probably want to know about it.

Dangerous error #2 is more serious. With an [R] flag you normally need an [L] as well, meaning "stop rewriting and proceed to the next module". Some flags carry an implied [L]; [R] (with or without exact number) does not.

The presentational error is the escaped slash. (But why only the first one? Was this a cut-and-paste?) Ordinarily a slash / does not need to be escaped in a regular expression. There are exceptions, but mod_rewrite is not one of them. It probably won't affect the execution of the rule; it just isn't necessary.

liorsi




msg:4577518
 5:57 pm on May 24, 2013 (gmt 0)

ok

now it's looking like this:
RewriteCond %{QUERY_STRING} ^id=13986$
RewriteRule ^/Front/Pages/pages.asp$ http://www.example.com/index.php/tours/holiday/40-selichot? [R=301]


still not found 404.
how much time it's take to apply the changes?

phranque




msg:4577534
 6:39 pm on May 24, 2013 (gmt 0)

you ignored almost everything lucy24 posted:
- leading slash
- non-escaped period
- L flag

liorsi




msg:4577539
 6:51 pm on May 24, 2013 (gmt 0)

RewriteCond %{QUERY_STRING} ^id=13986$
RewriteRule ^Front/Pages/pages.asp$ http://www.example.com/index.php/tours/holiday/40-selichot? [R=301, L]


i don't understand this:
- non-escaped period

phranque




msg:4577546
 7:26 pm on May 24, 2013 (gmt 0)

...pages\.asp$...

lucy24




msg:4577547
 7:31 pm on May 24, 2013 (gmt 0)

Escape = preceding backslash

\. = literal period (inherent to Regular Expressions, not only mod_rewrite)
. = any single character

Does your cms require the "index.php plus a whole bunch more path" format. Eeuw.

liorsi




msg:4577601
 9:49 pm on May 24, 2013 (gmt 0)

thanks for all it's working!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved