how to rewrite URL having multiple parameters - url

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');
}

Related

Re-writing URLs with an ending forward slash

I have a quick question about re-writing urls. I would like all my pages to be re-written as such
mysite.com/edit.php -> mysite.com/edit/
mysite.com/search.php -> mysite.com/search/
Along with that it should still be able to take parameters
mysite.com/edit.php -> mysite.com/edit/?id=2
This is what I have so far but it doesn't take the ending / so it's just mysite.com/edit
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
Also, as an extra, is it possible to not allow users to actually add the .php if they tried to? So for example if I had /edit.php and I got it working to do /edit/ or /edit and a user actually tried to type in /edit.php it wouldn't work.

Magento custom URL Rewrite not working

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

URL Rewriting doesn't rewrite automatically

I have this simple redirection on my website and it does not rewrite my url automatically, I have to type manual other URL to access it, what could be the problem, do I need to have something enabled in php.ini, below is the rewrite rule
RewriteEngine On
RewriteRule ^new-page-([^/]*)\.php$ /mypage.php?name=$1 [L]
If you are doing it in .htaccess you should also specify RewriteBase /.
Try
RewriteEngine On
RewriteBase /
RewriteRule ^new-page-([^/]*)\.php$ mypage.php?name=$1 [L]
This rewrites new-page-something.php tomypage.php?name=something internally.
ADDED:
Perhaps you want this:
RewriteEngine On
RewriteBase /
RewriteRule ^new-page-([^/]*)\.php$ mypage.php?name=$1 [L]
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD|TRACE)\ /mypage.php
RewriteCond %{QUERY_STRING} name=([^\&]*)
RewriteRule ^mypage.php$ new-page-%1.php? [R,L]
The first added RewriteCond checks whether the real request is requesting for /mypage.php to prevent a redirect loop.
The second added RewriteCond is used to match the query string for use in RewriteRule.
check your apache config (httpd.conf)
see whether it allowing to overriding the htaccess
http://httpd.apache.org/docs/2.0/howto/htaccess.html
I have the following link
www.preparationweb.com/Aptitude/Discussion/index.php?qid=26
I like it to appear it as
www.preparationweb.com/Aptitude/Discussion/26
Can you please provide me the code to be placed in .htaccess file according to the provided link. I have a godaddy hosting.

URL not rewritten in .htaccess when 'index.html' present

Here is a portion of the .htaccess rewrites:
RewriteCond %{QUERY_STRING} ^pid=directions_to_business$
RewriteRule ^$ directions? [NC,R=301,L]
So in essence, http://www.mybusiness.com/?pid=directions_to_business should redirect to http://www.mybusiness.com/directions. However when this url is given: http://www.mybusiness.com/index.html?pid=directions_to_business, the URL is not redirected.
I'm using a Rails app if that makes any difference.
Your code,
RewriteRule ^$ directions? [NC,R=301,L]
Only matches an empty request, i.e. the root (query strings aren't used for RewriteRule). You want this:
RewriteRule ^.*$ directions [NC,R=301,L,QSA]
Which will forward your query string as well (QSA), if you want http://www.mybusiness.com/?pid=directions_to_business&from=... to go to http://www.mybusiness.com/directions?from=....

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