Magento custom URL Rewrite not working - url

On my website there is a collection of pdf files for manuals, brochures, MSDS etc. The links to download these files are scattered across a "downloads" area, informational pages and product page. We update the brochures on a regular basis so in order to not have to update every single page where the file is linked from I need to know how to create a redirect where the old URL:
http://easypropondproducts.com/media/pdfs/EcoPondKitsBroch-MPF-109.pdf
will permanently redirect to the new URL
http://easypropondproducts.com/media/pdfs/EcoPondKitsBroch-MPF-512.pdf
I have tried custom URL rewrites and it doesn't seem to work how I have configured it:
Type: custom
ID Path: /media/pdfs/EcoPondKitsBroch-MPF-109.pdf
Request Path: /media/pdfs/EcoPondKitsBroch-MPF-109.pdf
Target Path: http://easypropondproducts.com/media/pdfs/EcoPondKitsBroch-MPF-512.pdf
Redirect: Permanent (301)
What am I doing wrong? Is there any way to do this?

You cannot rewrite files in the media folder by using Magentos internal URL Rewrite Management.
That's because URLs pointing to Magentos media (or skin or js) folder don't even reach the central entry point at index.php, but are served directly.
Take a look at Magentos root .htaccess file:
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
With your URL, the first RewriteCond is the one that doesn't match. This condition says "if the URL does NOT start with /media/ or /skin/ or /js/".
But your URL does start with /media/. Hence it will not be rewritten to index.php and cannot reach Magentos internal URL Rewrite Management.
To achieve what you want you could insert the following line right before the first RewriteCond:
Redirect 301 /media/pdfs/EcoPondKitsBroch-MPF-109.pdf /media/pdfs/EcoPondKitsBroch-MPF-512.pdf

Related

how to rewrite URL having multiple parameters

i have many pages having URL structure like this
http://yourwebsite.com/storename?oid=AA112&offid=6
how to make it SEO friendly URL as oid and offid denotes oid-orderid and offid-offerid.
these parameters refferes to a unique offers of a particular store which may change periodically
If you are using Apache, here is one possible solution.
Make a single entry point. Then you need to write a router that handles a URL string
htaccess like:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
and router what do you want. very simple example:
$requestURI = explode("/", $_SERVER['REQUEST_URI']);
if($requestURI[0] == 'index'){
include('views/index.php');
}

wildcard_charcters.sitename routing issues

i would like to incorporate wildcard characters to my site. so previously it was
www.mysite.com/user/mike or www.mysite.com/user/dave will look like
mike.mysite.com or dave.mysite.com. i tried .htacces rewriting but those were of rewriting for sub-domains and it was creating problems with css and images.I just want that too call user function with value we pass.I use RoR MVC framework.(i'm sure .htacces solve this issue but i don't know if we can give wildcards in routes too).
and i would like to keep other links normal like www.mysite/project/dashboard or www.mysite/project/messages.
Thanks in advance.
edit
i tried this but it dosent work, it's goes to site5s default page.
Options +FollowSymLinks
RewriteEngine On
RewriteCond ^(.*)$.example.com [NC]
RewriteRule ^(.*)$ http://example.com/user/$1 [R=301,L]'
ok, finnaly i was able to do it,there will be few things which you have to do first.
paste this code in .htaccess first of all.
Options +FollowSymLinks
RewriteEngine On
// enable rewriting
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ // Check for wildcard character before example.com
RewriteCond %1 !=www // check if www is not present in URL
RewriteRule ^(.*)$ http://www.example.com/user/%1/$1 [R=302,L] // Redirect URL and replace matched wildcard character "^(.+)" in place of "$1"
Now we have defined the rules for that, now it's turn of redirection. above code won't be able to work.
for that you have to create a wildcard sub domain in from your Cpanle. Create a sub domain *.example.com and point to your public_html(you subsite if t\redirected site is a child site)

I Want to Generate Search Engine Friendly urls

I Want to Generate Search Engine Friendly urls for eg:- say I have a link below like
http://www.apexengineeringproject.com/display_project.php?id=AP112&title=ADVANCED%20OFFICE%20AUTOMATION%20SYSTEM%20USING%20GSM%20AND%20MICROCONTROLLER
I Just want it to be
http://www.apexengineeringproject.com/display_project.php/AP112/ADVANCED%20OFFICE%20AUTOMATION%20SYSTEM%20USING%20GSM%20AND%20MICROCONTROLLER
I tried with rewrite in .htaccess but didnt succeeded even Im not getting how to GET parameters once link is converted to seo friendly.So anybody please help me in this situation.
EDIT:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} \/index\.php [NC]
RewriteRule (.*) apexengineeringproject.com [R=301,L]
RewriteRule ^display_project.php/([^/]+)/([^/]+) /display_project.php?id=$1&title=$2 [NC]
This is the content of my .htaccess file but problem is page gets loaded but not the styles and javascripts.
Most likely, you're referencing your script/style files using a relative file name. The browser will use the whole directory path up to the last slash before the query string for fetching relative paths.
For example, when using the page before rewrite;
http://www.apexengineeringproject.com/display_project.php
...and it looks for a script at scripts/test.js, the browser will fetch it from;
http://www.apexengineeringproject.com/scripts/test.js
When using the page after rewrite;
http://www.apexengineeringproject.com/display_project.php/AP112/ADVANCED%20OFFICE%20AUTOMATION%20SYSTEM%20USING%20GSM%20AND%20MICROCONTROLLER
...a fetch of the relative path scripts/test.js will fetch the file;
http://www.apexengineeringproject.com/display_project.php/AP112/scripts/test.js
...which presumably does not exist.
To fix the problem, just make your script paths and css paths relative to the server root, ie don't use scripts/test.js, instead use /scripts/test.js.
EDIT: Although I'd consider it slightly hacky, you could rewrite some files back to the root. Can't test this, but it should be close to what you want;
RewriteCond %{REQUEST_URI} \.(jpg|css|png|js)$ [NC]
RewriteRule display_project.php/[^/]*(.*) $1 [NC]

adding location as subdirectory to url with mod rewrite?

I working on project that displays item according to the location. First time user has to pick a location in order to search for an item. This location is saved as cookie for future reference. The url looks as following:
www.example.com/newyork
If the user is looking at an item that exists in New York, the url for that item is:
www.example.com/item/iphone
Above url works fine but there is one problem. If the above url is forwarded through an email to a first time user, This item does not exist because the location is not selected. I could forward user to different page to select location and then look for the item, but this is hassle for the user. So, I would like to change above url to
www.example.com/newyork/item/iphone
so that way I could use New York as location. How do I add a non-existing sub directory to a url? Canthis be done with PHP or done with mod_rewrite?
You can try doing a redirect, but you'll have to carefully craft the regular expression used to match /newyork/item/iphone. Then you can group out the newyork part and set a cookie and redirect the browser using the CO flag.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)/item/([^/]+)$ /item/$2 [L,R,CO=location:$1:example.com:/]
This will take a request like http://www.example.com/pittsburgh/item/iphone and extract the pittsburgh part, store it in a cookie named location (with the domain=example.com and path=/), then redirect the browser so the cookie gets stored by the browser and make the browser go to http://www.example.com/item/iphone
See the documentation for the CO flag for details about the syntax:
[CO=NAME:VALUE:DOMAIN:lifetime:path:secure:httponly]
Quick question. The acutal link without mod_rewrite rule is www.example.com/item.php/itemid=phone. Is it possible to rewrite this link to www.example.com/newyork/item.php/itemid=phone
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)/item.php/itemid=(.+)$ /item.php/itemid=$2 [L,R,CO=location:$1:example.com:/]

mod_rewrite is redirecting instedad of rewriting

I must be missing something obvious, but I can't make it work
I want to have nice urls with subdomains, but instead of some directories I want to read the subdomain's content from the file:
RewriteEngine On
RewriteBase /
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^subdomain.example.com
RewriteRule (.*) http://example.com/subdomain.php
These rules works, but if I enter subdomain.example.com I am redirected to example.com/subdomain.php - but I do not want this, I just want internally rewrite the url...
Thank you very much! I tried [QSA, L], do not work.
If you replace this:
RewriteRule (.*) http://example.com/subdomain.php
With this, I suspect it will work as you are expecting:
RewriteRule (.*) subdomain.php
There is no need to rewrite the domain unless you actually want to redirect to another domain, you only need to rewrite the request to point to the appropriate file. Indeed as you discovered rewriting the domain will cause a redirect. Normally RewriteRule matches all of the request after the domain, so just the path and query.
Rather than use mod rewrite for this, if you have access to the DNS controls of your domain, you could set a catchall subdomain with a wildcard (either '%' or '*') that directs to the same local directory. There, you could have a PHP script which all requests are directed to using:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php?p=$1 [L]
and this would run all the requests into that PHP file. There you can have something that checks the $_SERVER variables for the requested domain, and a checker to see the subdomain. There it could use something such as a file_get_contents() subroutine to forward the relevant data to the client, and have 404 or 403 header responses if a request is made that may be valid, but not to that subdomain.
hope that makes sense...

Resources