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:/]
Related
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');
}
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 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]
I would like to be able to access this URL on my website:
www.mysite.com/author/username
trough this one
www.mysite.com/username
Please consider that people should be able to access using the two url and that the "username" always change depending on the user.
What would be the best way to do it? htaccess rewrite?
Thank for your time!
Seems like it could be messy and box you in if your users create names that match paths that overlap with existing or future paths.
RewriteCond %{REQUEST_URI} ^/[a-z]+$ #1
RewriteCond %{REQUEST_FILENAME} !-f #2
RewriteRule ^/([a-z]+)$ /author/$1 [P] #3
try to restrict it as much as possible to your username pattern
only rewrite if the path doesn't already exist
proxy to the /author/username version of the 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